codecamp

Python List insert()方法

Python List 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']
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }