解压变量
# swap
a, b = b, a
# 支持tuple和list的解压
l = [1, 2]
a, b = l
# 在变量的组合中也可以生效
a, b, c = 1, 3, (4, 5)
# python会自动识别
a, b, (c, d), e = 1, 3, (4, 5), 7
缺省元素
_, _, (c, d), _ = 1, 3, (4, 5), 7
# 取值
a = {}
for _, v in a.items():
print(v)
压缩变量
data = ['wheel', 'factory1', 3, 4, 5, 6, '2020-02-02']
name, factory, *inch, date = data
print(inch)
联合使用
data = ['wheel', 'factory1', 3, 4, 5, 6, '2020-02-02']
name, factory, *_, date = data