将集添加到列表:list + = set和list = list + set之间的差异

时间:2017-12-23 23:22:28

标签: python

l = [1, 2, 3]
s = set([2, 3, 4])
l += s
print(l)  # Prints [1, 2, 3, 2, 3, 4]. Why?!
l = l +s  # Raises TypeError (as expected)

发生了什么?我希望将一个集合添加到列表中的尝试会导致TypeError。为什么+ =和+之间存在差异?

0 个答案:

没有答案