合并列表
# 方法一:append()
A = [91, 95, 97, 99]
B = [92, 93, 96, 98]
for i in A:
B.append(i)
print(B)
[92, 93, 96, 98, 91, 95, 97, 99]
# 方法二:extend()
A = [91, 95, 97, 99]
B = [92, 93, 96, 98]
A.extend(B)
print(A)
[91, 95, 97, 99, 92, 93, 96, 98]
# 方法三:‘+‘
# '+'与extend()区别为'+'生成新列表,extend()在原列表上合并
A = [91, 95, 97, 99]
B = [92, 93, 96, 98]
C = A+B
print(C)
[91, 95, 97, 99, 92, 93, 96, 98]
网友评论