Python示例拆箱元组或序列或可迭代使得元组可能比N个元素长,导致“值太多”无法解压”异常。1.解包任意长度的元组Python“星号表达式”可以用来解包任意长度的元组。example1.py>>>employee=('Lokesh','email@example.com','111-222-333','444-555-666')>>>name,email,*phone_numbers=employee>>>name'Lokesh'>>>email'email@example.com'>>>phone_numbers['111-222-333','444-555-666']example2.py>>>*elements,end=[1,2,3,4,5,6,7,8]>>>elements[1,2,3,4,5,6,7]>>>end82.unpacktuplesanddiscardunpackingvalues如果有元素数量不匹配,你会得到一个错误。example3.py>>>record=('Lokesh',37,72.45,(1,1,1981))>>>name,*_,(*_,year)=record#Onlyreadnameandyear>>>name'Lokesh'>>>year1981学习愉快!Python基础教程在SublimeEditor中配置Python环境在Python代码中添加注释在Python中使用变量Python中的数据类型Python中的关键字Python字符串操作Python中的列表操作Python中的元组操作Pythonmax()和min()–查找列表或数组中的最大和最小值Pythonfind最大的N(topN)或最小的N项Python在Python中使用httplib2读写CSV文件——HTTPGET和POST示例变量或参数Python拆箱Tuple——值太多无法拆包Pythonmultidict示例——映射单个键到字典中的多个值PythonOrderedDict-有序字典Python字典交集-比较两个字典Python优先级队列示例作者:分布式编程来源:https://zthinker.com/
