-
extend
extend()函数用于在列表末尾一次性追加一个序列中的多个值(用新列表扩展旧列表),这个序列是列表中具体的元素,而不是列表本身。
list1 = [1,2,3,4]
list2 = [5,6,7]
list1.extend(list2)
print(list1)
# 结果:
[1, 2, 3, 4, 5, 6, 7]
-
append
append()在列表末尾添加新对象,这个对象可以是列表本身。
list1 = [1,2,3,4]
list2 = [5,6,7]
list1.append(list2)
print(list1)
# 结果:
[1, 2, 3, 4, [5, 6, 7]]