现在位置: 首页 > Python 3 教程 > 正文

Python3 List insert()方法

Python3 列表 Python3 列表


描述

insert() 函数用于将指定对象插入列表的指定位置。

语法

insert()方法语法:

list.insert(index, obj)

参数

  • index -- 对象obj需要插入的索引位置。
  • obj -- 要插入列表中的对象。

返回值

该方法没有返回值,但会在列表指定位置插入对象。

实例

以下实例展示了 insert()函数的使用方法:

实例

#!/usr/bin/python3

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

以上实例输出结果如下:

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

Python3 列表 Python3 列表