标签: 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。为什么+ =和+之间存在差异?