3 python 操作列表

lists = ["aaa", "ccc", "ddd", "ggg"]
for lista in lists:
    print(lista)

for val in range(1,10): #创建数值列表 range(1,10)
    print(val)

lists1 = list(range(1,10)) #创建数字列表  [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(lists1)

lists2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(min(lists2))
print(max(lists2))
print(sum(lists2))

lists3 = [value**2 for value in range(1,11)] #列表解析
print(lists3)

lists2 = [1, 2, 3, 4, 5, 6, 7, 8, 9] #切片
for lists2on in lists2[0:3]:
    print(lists2on)

lists2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for lists2on in lists2[4:6]:
    print(lists2on)

lists2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for lists2on in lists2[:]:
    print(lists2on)

lists2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for lists2on in lists2[:]:
    print(lists2on)

lists3 = lists2[:]  #复制列表
for lists3on in lists3:
    print(lists3on)


发表评论

邮箱地址不会被公开。