x, y = 1, 2 x, y = y, x print(x,y) a, b = 2, 3 print(a, b) c, d = (4, 5) print(c, d) e, f = [6, 7] print(e, f) g, h = {8, 9} print(g, h) i, j = {'m': 10, 'n': 11} print(i, j)
3.剩余变量解构
带*的变量,会尽可能手机剩余数据放置在一个 列表中
1 2 3 4 5 6 7 8 9
a, *b, c = range(5) print(a, b, c) *b, c = range(5) print(b, c) b, *c = range(5) print(b, c) # 丢弃变量 _, *a, _ = range(5) print(a)