gpt4 book ai didi

python - 为什么添加到列表会做不同的事情?

转载 作者:太空狗 更新时间:2023-10-29 17:32:28 24 4
gpt4 key购买 nike

<分区>

>>> 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

我不明白为什么 list += (something)list = list + (something) 会做不同的事情。另外,为什么 += 将字符串拆分为要插入到列表中的字符?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com