【List】python列表中,append和extend的区别

a_list = [1,2,3]

a= [2]

a_ = a * 10

a_list.append(a_)

print(a_list) 

[1, 2, 3, [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]] 


a_list = [1,2,3]

a= [2]

a_ = a * 10

a_list.extend(a_)

print(a_list)

[1, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]

你可能感兴趣的:(笔记,python,python)