list = [
'hello'
,
'wrold'
]
# len 获取查询长度
length = len(list)
# append 添加一个新元素,到list的末尾
list.append(
'admin'
)
# pop删除指定位置的元素
list.pop(len(list)-1)
# insert指定位置添插入元素
#两个参数 1.要插入的位置 2.插入的内容
list.insert(len(list),
'admin'
)
#打印list
print
(list)
#[
'hello'
,
'wrold'
,
'admin'
]
#如果你输入的下标大于list长度则会自动=插入到list长度的位置
#即list.insert(len(list),
'admin'
)
list.insert(1000,
'admin'
)
print
(list[3]) #admin
# extend list追加合并
list = [123,456]
list1 = [789,101112]
a = list.extend(list1) #[123,456,789,101112]
#index list 找出第一个匹配项的的下标(索引位置) 返回下标
list = [123,456,456,
'b'
]
a = list.index(456)
#remove 删除第一个匹配项
list = [123,
'a'
,[1,3,4]]
list.remove([1,3,4]) # list = [123,
'a'
]
#resverse 反向list
list.resverse()
#sort 排序list
#list.sort(cmp=None, key=None, reverse=False)
list = [1,2,3,4,6,5]
list.sort()
list.sort(reverse = True)
list = [[1, 6], [2, 3], [3, 7]]
#声明函数
def second(item):
return
item[1]
list.sort(key = second)
list.sort(key = second,reverse = True)