1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| """ 序列 包含多项数据,按顺序排列 通过索引访问 常见的序列 字符串 列表 元组 列表和元素很相似 主要区别为元组不可变 列表可变 创建列表 [ele1,ele2,ele3 ...] 创建元组 (ele1,ele2,ele3 ...) """ my_list = ['name', 'age', 34] print(my_list) my_tuple = ('name', 'age', 44) print(my_tuple)
print(my_list[1]) print(my_tuple[2])
print(my_list[1:]) t1 = (1, 2, 3, 4, 5, 6, 7, 8, 9) print(t1[2:7:2])
l1 = ['a', 'b', 'c'] l2 = ['a', 'f', 'g'] print(l1 + l2) t1 = ('h', 'this', 'name') t2 = ('name', 't', 'r') print(t1 + t2)
l = ['you', 'are', 'good'] print(l * 2) t = ('oh', 'I', 'know') print(t * 3) """ 单个元素的元组 ('hei',) 后面要带逗号 要不然会当成字符串 """ print(('hei',) * 3 + ('come', 'here'))
print('you' in l) print('oh' not in t)
print(len(l)) print(len(t)) print(max(l), min(l)) print(max(t), min(t)) print(max((3, 4, 5, 11, 24, 33, 66, 31, 2)))
values = 10, 20, 30 print(values) print(type(values)) a_tuple = tuple(range(1, 10, 2)) a, b, c, d, e = a_tuple print(a, b, c, d, e) m, n = ['hello', 'world'] print(m, n)
x, y, z = 10, 20, 30 print(x, y, z) x, y, z = y, z, x print(x, y, z)
first, second, *rest = range(10) print(first, second) print(rest)
|