>>> second_matrix = [(6, 9), (5, 8), (4, 7)] # 列表中是元组
>>> res = [1, 2, 3]
# 情况一
>>> res += second_matrix.pop(0)
>>> res
[1, 2, 3, 6, 9]
# 情况二
>>> [1, 2, 3]+(6,9)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "tuple") to list
# 情况三
>>> second_matrix = [(6, 9), (5, 8), (4, 7)]
>>> [1, 2, 3]+second_matrix.pop(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "tuple") to list
>>>
>>> type(second_matrix)
<class 'list'>
情况一不是很理解,难道是因为second_matrix本质还是列表吗?所以列表可以进行运算如果情况一是因为列表,那么情况三也是列表相加减啊
求大神赐教!!!