The n elements are decomposed from an iterative object, but the length of an iterative object may exceed N, and an exception of "too many decomposition values" appears.
Use "* expression" to resolve the problem:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb, 22:43:06) [MSC v.1600 32bit (Intel)] on Win32type"Copyright","credits" or "license ()" forMore information.>>> *headdata,current=[10,3,2,6,8,5]#* Modified variables are located in the first position of the list, easy to separate head and tail>>>headdata[10, 3, 2, 6, 8]>>> Current5>>> record= ('Xiao Ming','[email protected]','13288888888','13566666666')>>> Name,email,*phone_numbers=record#* The modified variable is in the last position of the list>>>name'Xiao Ming'>>>Email'[email protected]'>>>phone_numbers['13288888888','13566666666']>>> line='nobody:*:-2:-3:unpriviledged User:/var/empty:/usr/bin/false'>>> Uname,*fields,homedir,sh=line.split (':')#* The modified variable is in the middle position and is combined with the string manipulation operation>>>uname'Nobody'>>>Homedir'/var/empty'>>>SH'/usr/bin/false'>>>fields['*','-2','-3','unpriviledged User']>>> record=['Lucy', 50,123.4, (12,13,2016)]>>> name,*_, (*_,year) =record#discard some of the decomposed values>>>name'Lucy'>>> Year2016>>>
* Style usage is especially useful when iterating over a variable-length tuple sequence:
"Python Cookbook" "Data Structure and algorithm" 2 explode elements from an arbitrary length of an iterative object