String is Immutable.
Strings are Immutable:
The String in python are immutable. You can not change an existing character of a string. Let us consider :
indexing |
Type error st object does not support item assignment. The object in this case is the string st and the item is character you try to assign , an object is the same thing as a value and item is one of the value of a sequence. To achieve changes like modification in a String, we can create new String.
In the above example str1 and str2 have the same contents, Python uses one object for each string which has same content.
Comments
Post a Comment