num0 = 'xuxu'
num2 = 'liming'
num3= 'dazui'
num4 = 'hh'
num5 = 'ranran'
a = ['xuxu','liming','dazui','hh','ranran']
b = [1,2,3,4,5,6,7,8,9]
#增删改查
#查,切片
#print(a[1:])#一取到最后['liming', 'dazui', 'hh', 'ranran']
#print(a[1:3])#取不到3,取到1,2,['liming', 'dazui']
#print(a[1:-1])#取到倒数第二个,['liming', 'dazui', 'hh']
#print(b[1::2])#步长为2的取,[2, 4, 6, 8]
#print(a[1::-1])#反向取,['liming', 'xuxu']
#print(a[-1])
#print(a[-2::-1])#['hh', 'dazui', 'liming', 'xuxu']
#print(a[1:-1:-2])
#添加 append insert
#a.append('yuanyuan')#在末尾自动添加
#print(a)
#a.insert(1,'yuanyuan')#将数据插入到任意一个地方
#print(a)
#修改
#a[1] = 'xuxu2'
#a[1:3] = ['a','b']
#print(a)
#删除 remove pop del
#a.remove(a[1])
#print(a)
#a.remove('xuxu')
#print(a)
#b.remove([1,2])不可以是列表
#print(b)
#print(a.pop(1))
#print(a)
#del a[1]
#print(a)
#del a
#print(a)
#count:计算某元素出现次数
#t = [1,2,2,3,5,6,5,6,9,9,9]
#print(t.count(9))
#extend
#a = [1, 2, 3]
#b = [4, 5, 6]
#a.extend(b)
#print(a)
#print(b)
'''
append和extend都仅只可以接收一个参数,
append 任意,甚至是tuple
extend 只能是一个可迭代对象
'''
# index # 根据内容找位置
'''
str.index(str, beg=0, end=len(string))
str – 指定检索的字符串
beg – 开始索引,默认为0。
end – 结束索引,默认为字符串的长度。
'''
#a = ['wuchao', 'jinxin', 'xiaohu','ligang', 'sanpang', 'ligang', ['wuchao', 'jinxin']]
#print(a.index('xiaohu'))
#print(a.index('ligang'))
#print(a.index('ligang',4))
# reverse, reverse() 函数用于反向列表中元素
#a = ['wuchao', 'jinxin', 'xiaohu','ligang', 'sanpang', 'ligang']
#a.reverse()
#print(a)
c = [2,1,6,3,5,9,4,0]
c.sort()
print(c)
列表嵌套
b = [[1,2,3],4,5,6,7,8,9]
b[0][2]=10
print(b)
>>>
b = [[1,2,10],4,5,6,7,8,9]