TypeError: 'str' object does not support item assignment
2018-09-02 17:35
851 查看
代码如下时会报告TypeError: 'str' object does not support item assignment:
[code]str = "My friend and i hang out together" str[14] = 'I'
这种错误的原因是string(区别于list)是一种不可变的数据类型,应该用:
[code]str = str[:14] + 'I' + out_str[15:]
代替原来的第2行,就可以解决这个问题。
阅读更多相关文章推荐
- TypeError: 'str' object does not support item assignment 的解决方法
- TypeError: 'ItemMeta' object does not support item assignment
- python 报错TypeError: 'range' object does not support item assignment,解决方法
- theano 中出现 TypeError: 'TensorVariable' object does not support item assignment
- TypeError: 'dict_keys' object does not support indexing
- TypeError: 'str' does not support the buffer interface
- python提示错误TypeError: 'dict_keys' object does not support indexing
- Python笔记002——错误TypeError: 'str' does not support the buffer interface
- Python List find方法报错 TypeError: 'str' does not support the buffer interface
- Python+client_connection.sendall(http_resp)+TypeError: 'str' does not support the buffer interface
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- python socket send 错误:TypeError: 'str' does not support the buffer interface
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- Strange SQLAlchemy error message: TypeError: 'dict' object does not support indexing
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- python object does not support item assignment
- TypeError:’str’ does not support the buffer interface
- TypeError: 'dict_keys' object does not support indexing
- TypeError: 'dict_keys' object does not support indexing