标签归档:cookbook

pycookbook-数据结构

解压序列赋值给多个变量

In [32]: b = ['qwe','asd']

In [33]: q,a = b

In [34]: a
Out[34]: 'asd'

In [35]: q
Out[35]: 'qwe'

如果变量数跟序列元素数不一致,会出现异常

In [36]: q,a,z = b
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-5bedc90bd5b2> in <module>()
----> 1 q,a,z = b

ValueError: not enough values to unpack (expected 3, got 2)

继续阅读