@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 1466 / 12833)
This is sometimes called tuple unpacking.
Exemple
>>> marx_tuple = ( 'Groucho', 'Chico', 'Harpo' )
>>> a, b, c = marx_tuple
>>> a
'Groucho'
>>> b
'Chico'
>>> c
'Harpo'
Est-ce utile pour vérifier le Nième élément du 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')
résultat
Success time: 0 memory: 23304 signal:0
('Groucho', 'Chico', 'Harpo')
Chico
co inside
Recommended Posts