Python 列表 insert() 方法


描述

Python 列表 insert() 方法將指定對象插入到列表中的指定位置。

語法

insert() 方法語法:

L.insert(index,obj)

參數

  • index -- 對象obj需要插入的索引值。
  • obj -- 要插入列表中的對象。

返回值

該方法沒有返回值,但會在列表指定位置插入指定對象。

實例

以下實例展示了 insert() 方法的使用方法:

#!/usr/bin/python3

L1 = ['Google', 'Runoob', 'Taobao']
L1.insert(1, 'Baidu')
print ('列表插入元素后為 : ', L1)

以上實例輸出結果如下:

列表插入元素后為 :  ['Google', 'Baidu', 'Runoob', 'Taobao']


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM