Python list 增加/插入元素的说明

http://blog.csdn.net/cnmilan/article/details/9259343

在Python中append 用来向 list 的末尾追加单个元素,如果增加的元素是一个list,那么这个list将作为一个整体进行追加。
例如:
Python代码
li=['a', 'b']   
li.append([2,'d'])   
li.append('e')   
#输出为:['a', 'b', [2, 'd'], 'e']  
 

在Python中 insert 用来将单个元素插入到 list 中。数值参数是插入点的索引。
例如:
#Python代码
li=['a', 'b']   
li.insert(0,"c")   
#输出为:['c', 'a', 'b']  
 

Python中 extend 用来连接 list。
例如:
Python代码
li=['a','b']   
li.extend([2,'e'])   
#输出为:['a', 'b', 2, 'e']  

原文地址:https://www.cnblogs.com/ymjyqsx/p/7524924.html