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 concatenate list (not "tuple") to list
1 a = [1,2] 2 a.append((1,2)) 3 print(a) 4 运行结果: 5 [1, 2, (1, 2)]
a = [1,2] a.extend([5,6,7]) print(a) 运行结果: [1, 2, 5, 6, 7]
本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/articles/9382455.html