Python List insert()方法
生活随笔
收集整理的這篇文章主要介紹了
Python List insert()方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Python 列表
描述
insert() 函數用于將指定對象插入列表的指定位置。
語法
insert()方法語法:
list.insert(index, obj)
參數
? index – 對象 obj 需要插入的索引位置。
? obj – 要插入列表中的對象。
返回值
該方法沒有返回值,但會在列表指定位置插入對象。
實例
以下實例展示了 insert()函數的使用方法:
實例
#!/usr/bin/python aList = [123, ‘xyz’, ‘zara’, ‘abc’] aList.insert( 3, 2009) print "Final List : ", aList
以上實例輸出結果如下:
Final List : [123, ‘xyz’, ‘zara’, 2009, ‘abc’]
總結
以上是生活随笔為你收集整理的Python List insert()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 不拦截指定路径_控制层访问拦截
- 下一篇: 实例18:python