Python 简介
String objects (byte strings, as well as text, AKA Unicode, ones) are immutable: attempting to rebind or delete an item or slice of a string raises an exception.
重新绑定(bind)引发异常的字符串对象意味着什么?
>>> a="hello"
>>> a="world"
>>>
我是否刚刚成功将变量 a
从字符串对象 'hello'
重新绑定(bind)到 'world'
?
谢谢。
最佳答案
您所做的是删除“hello”字符串对象并将其替换为“world”字符串对象。文档的意思是这样的:
>>> a="hello"
>>> a[3]="t" # does not produce helto
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>>
关于python - 重新绑定(bind)引发异常的字符串对象意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46187708/