python成长之list篇

list=[ obj1,obj2,......  ]

记住四大类:

增 删 改 查(数据四大定律)

1 增

append(object):在list末尾添加object

insert(index,object):在index插入object

extend(target_list):在原list末尾插入target_list的所有元素

2 删

remove(object) :在list中如果有一个或多个,那么删除第一个出现的object,如果list不存在object,那么程序会报错

pop(index):(如果index不写,那么默认删除list末尾的元素)删除index位置的元素

clear():删除list所有的元素

命令模式:del object 将object所在的内存信息删除

3 改

直接list[index]=object  就可以

sort([reverse=[True or False]]) :对list进行升序。默认reverse=false,即排序之后不反转list,为True则排序之后反转list。

reverse(): 对list进行反转

4 查

len(list):查询list的长度

list.count(object):返回obj在list中出现的次数

list.index(object) :返回object在list中的索引值,不存在程序会报错

(5:迭代

 for para in list :

  

posted @ 2018-09-14 16:12  tool人  阅读(247)  评论(0)    收藏  举报