python_109_切片补充和list函数
#切片补充 a=[1,2,3,4,5,6,7,8] print(a[::2])#隔一个取一个元素 [1, 3, 5, 7] print(a[::-1])#将列表或元祖颠倒过来 [8, 7, 6, 5, 4, 3, 2, 1] b=tuple(a) print(b)#(1, 2, 3, 4, 5, 6, 7, 8) print(b[::2])#(1, 3, 5, 7) print(b[::-1])#(8, 7, 6, 5, 4, 3, 2, 1) c=list(b) print(c[::3])#[1, 4, 7] print(c[::-2])#[8, 6, 4, 2] # list函数常用在数据处理中实体化迭代器或生成器 gen=range(10) print(gen)#range(0, 10) print(list(gen))#[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]