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

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
>>>
主站蜘蛛池模板: 阳泉市| 澄城县| 珠海市| 永吉县| 永嘉县| 松原市| 无极县| 汽车| 阿坝县| 黄冈市| 社会| 油尖旺区| 临漳县| 青州市| 二连浩特市| 云林县| 恩施市| 定州市| 芜湖市| 宝丰县| 理塘县| 玉树县| 锡林郭勒盟| 齐河县| 卢湾区| 伊春市| 宣汉县| 外汇| 金秀| 漾濞| 梅河口市| 阳江市| 金阳县| 梁河县| 老河口市| 扶绥县| 镇巴县| 哈巴河县| 昭苏县| 宁晋县| 盐津县|