@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 1466 / 12833)
This is sometimes called tuple unpacking.
Example
>>> marx_tuple = ( 'Groucho', 'Chico', 'Harpo' )
>>> a, b, c = marx_tuple
>>> a
'Groucho'
>>> b
'Chico'
>>> c
'Harpo'
Is it useful for checking the Nth item of tuple?
http://ideone.com/vuW96Q
marx_tuple = ( 'Groucho', 'Chico', 'Harpo' )
print(marx_tuple)
_, item2nd, _ = marx_tuple
print(item2nd)
if 'co' in item2nd:
print('co inside')
result
Success time: 0 memory: 23304 signal:0
('Groucho', 'Chico', 'Harpo')
Chico
co inside
Recommended Posts