Python中extend()与append()的差别

Python中自带的extend()append()方法的功能类似但在处理多个列表时,这两种方法的处理结果是完全不同的

>>>a=[1 , 2 , 3]
>>>b=[4 , 5 , 6]
>>>a.append(b)
>>>a
[1 , 2 , 3 , [4 , 5 , 6]]
>>>a.extend(b)
>>>a
[1 , 2 , 3 , 4 ,5 ,6]

猜你喜欢

转载自blog.csdn.net/sun830910/article/details/84307589
今日推荐