Python list insert()方法代码示例:# www.cnpython.com Python中文网
# 下面演示代码为最新 Python3.X 环境下进行
>>> lis = [1,2,3,4,5]
>>> lis.insert(1, 'cnpython') # 在lis列表的索引1位置上插入字符串 'cnpython'
>>> print(lis)
[1, 'cnpython', 2, 3, 4, 5]
>>>
总结:
CNPYTHON提示:在上面输出结果中可以看到,字符串"cnpython"已经被插入到了列表的索引1位置上了,你可以用 lis[1] 取一下值,看下结果。
|