如果append和extend添加一个元素时,是看不出区别的,当添加多个元素就看出区别了
alist=[0,1,2,3,4,5,6]
alist.extend([7,8,9])
print(alist)
此时 alist 输出的结果为:[0,1,2,3,4,5,6,7,8,9]
extend若为列表,将列表元素,在尾部逐一加入,
若为字典,将字典key值,在尾部逐一加入
alist=[0,1,2,3]
bdict={"name":"lwb","age":20}
alist.extend(bdict)
print(alist)
此时 alist 输出:[0, 1, 2, 3, ‘name’, ‘age’]
blist=[0,1,2,3,4,5,6]
blist.append([7,8,9])
print(blist)
此时 blist 输出的结果为:[0,1,2,3,4,5,6,[ 7,8,9 ] ]