a = [1,2] c = a + [3,4] print(c) 输入出:[1, 2, 3, 4] a = [1,2] c = a + [3,4] #就地加 a += [3,4] print(a) 输出结果: [1, 2, 3, 4] a = [1,2] # c = a + (3,4) #就地加 a += [3,4] print(a) 运行提示错误: TypeError: can only
c = a + [3,4]
print(c)
输入出:[1, 2, 3, 4]
c = a + [3,4]
#就地加
a += [3,4]
print(a)
输出结果:
[1, 2, 3, 4]
# c = a + (3,4)
#就地加
a += [3,4]
print(a)
运行提示错误:
TypeError: can only concatenate list (not "tuple") to list
2 a.append((1,2))
3 print(a)
4 运行结果:
5 [1, 2, (1, 2)]
a.extend([5,6,7])
print(a)
运行结果:
[1, 2, 5, 6, 7]