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

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
>>>
主站蜘蛛池模板: 泰安市| 湖口县| 曲周县| 漳浦县| 赞皇县| 玛沁县| 青阳县| 陈巴尔虎旗| 玛曲县| 陆良县| 河东区| 西安市| 宁城县| 山阴县| 五大连池市| 弥勒县| 山阳县| 黎城县| 金寨县| 海宁市| 哈尔滨市| 依安县| 临武县| 青岛市| 城步| 原阳县| 简阳市| 稻城县| 靖安县| 景谷| 巴马| 南丰县| 清涧县| 通州区| 辽阳县| 尼勒克县| 张家港市| 贵溪市| 密云县| 南阳市| 海安县|