KnowledgeBoat Logo

Computer Science

Assertion. Modifying a string creates another string internally but modifying a list does not create a new list.

Reason. Strings are immutable types while lists are mutable types of python.

Python String Manipulation

2 Likes

Answer

(a)

Both Assertion and Reason are true and Reason is the correct explanation of Assertion.

Explanation
In Python, strings are immutable, meaning once they are created, their contents cannot be changed. Whenever we modify a string, python creates a new string object to hold the modified contents, leaving the original string unchanged. On the other hand, lists in python are mutable, meaning we can modify their contents after they have been created. When we modify a list, python does not create a new list object. Instead, it modifies the existing list object in place.

Answered By

2 Likes


Related Questions