pythonreference.com
search statements, functions, methods, exceptions*
hide categories
multiple target assignment
assign multiple values to individual variables
mylist = [1, 2, 3] a, b, c = mylist # "unpack" 3 list values print(b) # 2
[values in a container] -> [variable names]
|
A convenience statement that allows "unpacking" of values from a list, tuple or other ordered container, assigned to individual variable names. The number of variable names on the left must match the number of values on the right, otherwise a ValueError will occur.