python列表多重赋值
1.列表多重赋值常规方法
>>> cat = ['fat', 'black', 'loud']
>>> size = cat[0]
>>> color = cat[1]
>>> disposition = cat[2]
2.列表多重赋值技巧
'''
Python大型免费公开课,适合初学者入门
加QQ群:579817333 获取学习资料及必备软件。
'''
>>> cat = ['fat', 'black', 'loud']
>>> size, color, disposition = cat
3.注意:变量的数目和列表的长度必须严格相等,否则 Python 将给出 ValueError
>>> cat = ['fat', 'black', 'loud']
>>> size, color, disposition, name = cat
Traceback (most recent call last):
File "<pyshell#84>", line 1, in <module>
size, color, disposition, name = cat
ValueError: need more than 3 values to unpack