Python¶ 格式化输出¶ 1 2 3print("output:", a, b) print(f"output: {a} {b}") print("output: {} {}".format(a, b)) 切片¶ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18>>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> a[2:3] [2] >>> a[5:9] [5, 6, 7, 8] >>> a[5:-1] [5, 6, 7, 8] >>> a[-5:9] [5, 6, 7, 8] >>> a[-5:-1] [5, 6, 7, 8] >>> a[:5] [0, 1, 2, 3, 4] >>> a[5:] [5, 6, 7, 8, 9] >>> a[100:] [] 扩展切片 a[start:stop:step]: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16>>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> a[0:6:2] [0, 2, 4] >>> a[::2] [0, 2, 4, 6, 8] >>> a[:-2:2] [0, 2, 4, 6] >>> a[4::2] [4, 6, 8] >>> a[5::-1] [5, 4, 3, 2, 1, 0] >>> a[:4:-2] [9, 7, 5] >>> a[::-1] [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]