1.分解为单独变量
data = ['yxuang', 50, 95.5, (2011, 12, 21)]
name, age, score, date = data
print(name, age, score, date)
yxuang 50 95.5 (2011, 12, 21)
2.丢弃某些值
data = ['yxuang', 50, 95.5, (2011, 12, 21)]
_, age, score, _ = data
print(age, score)
50 95.5
3.分解N个元素
data = ['yxuang', 50, 95.5, (2011, 12, 21)]
first, *middle, last = data
print(first, middle, last)
yxuang [50, 95.5] (2011, 12, 21)
4.丢弃多个值
data = ['yxuang', 50, 95.5, (2011, 12, 21)]
name, _, (_, day) = data
print(name, day)
yxuang 21
网友评论