html tool

2017年9月27日星期三

python list 在指定位置增加key

http://www.runoob.com/python/att-list-insert.html

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

没有评论:

发表评论