首页 > 移动平台 > 详细

python中append、extend、和insert的区别

时间:2019-08-06 21:14:30      阅读:179      评论:0      收藏:0      [点我收藏+]
a_list = [x for x in range(1, 11)]
print(a_list)
a_list.append(sdadfewf)  # 将整个字符串放到列表的最后
print(a_list)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ‘sdadfewf‘]

b_list = [x for x in range(1, 11)]
print(b_list)
b_list.extend(sdadfewf)  # 将字符串中的每个元素放到列表的最后
print(b_list)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ‘s‘, ‘d‘, ‘a‘, ‘d‘, ‘f‘, ‘e‘, ‘w‘, ‘f‘]

c_list = [x for x in range(1, 11)]
print(c_list)
c_list.insert(3, sdadfewf)  # 将整个字符串插入到列表索引为3的位置
print(c_list)
# [1, 2, 3, ‘sdadfewf‘, 4, 5, 6, 7, 8, 9, 10]

 

python中append、extend、和insert的区别

原文:https://www.cnblogs.com/yang901112/p/11311793.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!