%解压序列到不同的变量中
1
x = ('Christopher', 'Brooks', 'brooksch@umich.edu') 2 fname, lname, email = x

 

1 fname
'Christopher'

1 lname
'Brooks'

%确保变量的数量和解压的值相同
1
x = ('Christopher', 'Brooks', 'brooksch@umich.edu', 'Ann Arbor') 2 fname, lname, email = x
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-9ce70064f53e> in <module>()
      1 x = ('Christopher', 'Brooks', 'brooksch@umich.edu', 'Ann Arbor')
----> 2 fname, lname, email = x

ValueError: too many values to unpack (expected 3)

 

posted on 2018-03-05 19:30  郑哲  阅读(75)  评论(0编辑  收藏  举报