赋值与解包

# python3.6.8

x, y = (1, 2)
print(x, y) # 1 2

x, y = (1, 2, 3)
print(x, y) # ValueError: too many values to unpack (expected 2)

x, *y = (1, 2, 3)
print(x, y) # 1 [2, 3]

x, *y, z = (1, 2, 3, 4)
print(x, y, z) # 1 [2, 3] 4

 

posted @ 2021-03-31 09:58  shulongshuyue  阅读(97)  评论(0编辑  收藏  举报