Can strings be changed in Python 3?
There is a method for changing strings: replace, for example:
a = 'lkjhgfdsa' a.replace('l','123')' 123kjhgfdsa' #返回结果
As can be seen from the above example, str can also be changed. but! ! !
This change does not really change the original string, but is equivalent to creating a new string:
>>> a = 'lkjhgfdsa' >>> b = a.replace('l','123') >>> a 'lkjhgfdsa' >>> b '123kjhgfdsa'
From the above example, the value of a has not been changed. We copy the "modified" string to b. It can be seen that a and b are completely different.
Summary: Strings cannot be changed in Python 3. If you use the str.replace method to change a string, the original string will remain unchanged and a new changed string will be created.
For more related articles, can strings be changed in Python3, please pay attention to the PHP Chinese website!