描述
insert() 函数用于将指定对象插入列表的指定位置。
语法
insert()方法语法:
list.insert(index, obj)
参数
index -- 对象 obj 需要插入的索引位置。
obj -- 要插入列表中的对象。
返回值
该方法没有返回值,但会在列表指定位置插入对象。
实例
以下实例展示了 insert()函数的使用方法:
#!/usr/bin/<a style='color:#f60; text-decoration:underline;' href="https://www.php.cn/zt/15730.html" target="_blank">python</a> aList = [123, 'xyz', 'zara', 'abc'] aList.insert( 3, 2009) print "Final List : ", aList
以上实例输出结果如下:
Final List : [123, 'xyz', 'zara', 2009, 'abc']
众多python培训视频,尽在python学习网,欢迎在线学习!
以上就是python中insert用法是什么的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号