小编mas*_*ley的帖子

如果x是list,为什么x + ="ha"可以工作,而x = x +"ha"会抛出异常?

从我所知的很少,+ op for lists只需要第二个操作数可迭代,"ha"显然是.

在代码中:

>>> x = []
>>> x += "ha"
>>> x
['h', 'a']
>>> x = x + "ha"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "str") to list
Run Code Online (Sandbox Code Playgroud)

python list operators

46
推荐指数
3
解决办法
2545
查看次数

标签 统计

list ×1

operators ×1

python ×1