python列表

python列表

list = ['red', 'green', 'blue', 'yellow', 'white', 'black']
list[0] #访问
list[1] = "pink"   #更新
del list[3] #删除
list[1:3] #截取

python列表内置函数

1、len(list)

列表元素长度

2、max(list)

返回列表元素的最大值

3、min(list)

返回列表元素的最小值

4、list(seq)

将元组转换成列表

python列表内置方法

1、list.append(obj)

在列表末尾添加新的对象

list.append('black')

2、list.count(obj)

统计某个元素在列表中出现的次数

3、list.extend(seq)

在列表末尾添加多个元素

4、list.index(obj)

从列表中找到某个元素的索引值

5、list.insert(index.obj)

将对象插入到列表,index为列表的位置

6、list.Pop([index=-1])

移除列表中的一个元素(默认为最后一个元素)

7、list.remove(obj)

移除列表中某一个值,如果匹配到多个,只删除第一个,返回删除的元素值

8、list.reverse()

反向列表中的元素

9、list.sort(reverse=true)

倒序排列,改变原列表

10、list.sorted()

排列,不改变原列表

11、list.clear()

清空列表

12、list.copy()

复制列表

12、list(range())

创建数字列表

range()

一个参数 (n)循环n次

两个参数(m,n) 创建从[m,n)的数

三个参数 (m,n,2) 创建从[m,n)中的偶数

原文地址:https://www.cnblogs.com/cupid10/p/14291905.html