python3 列表 函数

时间:2023-03-08 22:24:11

python3中list的所有函数

list是有序的,元素个数无限的,元素类型多样的,可变的

增加

# 'append',  增加对象
# 'insert', 指定位置增加
# 'extend', 增加可迭代对象 删除
# 'clear', 删除所有的
# 'remove', 删除指定的元素,不存在会报错ValueError
# 'pop', 弹出末尾的
# del list[k] 删除指定位置的元素 修改
list[k]=新值 # 'copy', 拷贝浅 # 查找
# 'count',
# 'index', # 'reverse', 逆序
# 'sort' 按照asc码来排序 注意copy是浅拷贝:
 a = ['d', 1, 'c', ['h'], 'a']
b = a
a[3][0] = 'mmm'
print(a)
print(b) a 和 b都变成
['d', 1, 'c', ['mmm'], 'a']

对a的操作会影响到b的内容