python使用insert添加列表元素

341次阅读
没有评论

python使用insert添加列表元素

说明

1、index表示指定位置的索引值,insert()将p_object插入listname列表第index要素的位置。

2、如果要添加的是序列,则insert()将该序列作为整体插入列表的指定位置。

语法

listname.insert(index, p_object)

实例

name_list = ['大伟', '小伟', '小小伟']
name_list.insert(1, 'Jack')
print(name_list)
name_list.insert(2, ['test', 'test1'])
print(name_list)
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-04-17发表,共计324字。
新手QQ群:570568346,欢迎进群讨论 Python51学习