python23 Append 和extend 的区别

# 列表中的extend和append 的使用

a = [1, 2, 3, 4, 5, 6]

b = [7, 8]

# extend 相当于合并

a.extend(b)

print(a)

# append相当于把一个整体进行添加

c = [1, 2, 3, 4, 5, 6]

d = [7, 8]

c.append(d)

print(c)

扫描二维码关注公众号,回复: 4525613 查看本文章

'''

[1, 2, 3, 4, 5, 6, 7, 8]

[1, 2, 3, 4, 5, 6, [7, 8]]

'''

 

如有疑问,请发邮件:[email protected]


github:https://github.com/wangrui0/

猜你喜欢

转载自blog.csdn.net/qq_35524586/article/details/85016339
今日推荐