Python3 列表
描述
insert() 函數(shù)用于將指定對象插入列表的指定位置。
語法
insert()方法語法:
list.insert(index, obj)
參數(shù)
- index -- 對象obj需要插入的索引位置。
- obj -- 要插入列表中的對象。
返回值
該方法沒有返回值,但會在列表指定位置插入對象。
實例
以下實例展示了 insert()函數(shù)的使用方法:
#!/usr/bin/python3
list1 = ['Google', 'W3CSchool', 'Taobao']
list1.insert(1, 'Baidu')
print ('列表插入元素后為 : ', list1)
以上實例輸出結(jié)果如下:
列表插入元素后為 : ['Google', 'Baidu', 'W3CSchool', 'Taobao']
更多建議: