码迷,mamicode.com
首页 > 移动开发 > 详细

python list的extend和append方法

时间:2019-03-16 09:50:25      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:nts   html   tty   elements   ocs   doc   ted   end   iterable   

append: Appends object at the end.

x = [1, 2, 3]
x.append([4, 5])
print (x)

gives you: [1, 2, 3, [4, 5]]


extend: Extends list by appending elements from the iterable.

x = [1, 2, 3]
x.extend([4, 5])
print (x)

gives you: [1, 2, 3, 4, 5]

python list的extend和append方法

标签:nts   html   tty   elements   ocs   doc   ted   end   iterable   

原文地址:https://www.cnblogs.com/zywscq/p/10540533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!