>>> aList = []
>>> aList += 'chicken'
>>> aList
['c', 'h', 'i', 'c', 'k', 'e', 'n']
>>> aList = aList + 'hello'
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
aList = aList + 'hello'
TypeError: can only concatenate list (not "str") to list
我不明白为什么要做 alist += (something)
和list = list + (something)
做不同的事情。另外,为什么要将+=
字符串拆分为要插入到列表中的字符?