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
Assertion. Lists and Tuples are similar sequence types of Python, yet they are two different data types.
Reason. List sequences are mutable and Tuple sequences are immutable.
Assertion. Modifying a string creates another string internally but modifying a list does not create a new list.
Reason. Strings store characters while lists can store any type of data.
Assertion. Dictionaries are mutable, hence its keys can be easily changed.
Reason. Mutability means a value can be changed in place without having to create new storage for the changed value.
Assertion. Dictionaries are mutable but their keys are immutable.
Reason. The values of a dictionary can change but keys of dictionary cannot be changed because through them data is hashed.