官术网_书友最值得收藏!

Strings are immutable

Strings are immutable, meaning we can't change the values. Refer to the given example:

>>> welcome = 'Hello, John!'
>>> welcome[0] = 'Y'
TypeError: 'str' object does not support item assignment

As the strings are immutable; we cannot change an existing string. But we can create a new string that will be different from the original:

>>> str1 = 'Hello John'
>>> new_str = 'Welcome' + str1[5:]
>>> print(str1)
Hello John
>>> print(new_str)
Welcome John
>>>
主站蜘蛛池模板: 偏关县| 梁山县| 乌鲁木齐县| 兴安盟| 永春县| 北辰区| 烟台市| 洛南县| 和顺县| 桦川县| 霍州市| 堆龙德庆县| 梓潼县| 铜川市| 阳江市| 泗洪县| 府谷县| 平阴县| 隆林| 麦盖提县| 安陆市| 津南区| 阆中市| 五华县| 沽源县| 肇庆市| 阜平县| 沙田区| 沭阳县| 南丰县| 元阳县| 邹平县| 神木县| 拉孜县| 敖汉旗| 山东省| 聊城市| 和静县| 徐州市| 寿光市| 通山县|