网络编程
位置:首页>> 网络编程>> Python编程>> python中如何使用insert函数

python中如何使用insert函数

作者:python大师  发布时间:2023-08-02 17:04:43 

标签:python,insert,函数

这篇文章主要介绍了python中如何使用insert函数,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

描述

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']

来源:https://www.cnblogs.com/daniumiqi/p/12155975.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com