Oct-15-2017, 09:48 PM
eventually you can use named tupe
from collections import namedtuple Pet = namedtuple('Pet', ['name', 'animal', 'weight']) pets = (Pet('Garfield', 'cat', 4), Pet('Pluto', 'dog', 10)) for mypet in pets: print(mypet) print('{} is a {} and its weight is {}'.format(*mypet)) print(mypet.name, mypet.animal, mypet.weight)
Output:Pet(name='Garfield', animal='cat', weight=4)
Garfield is a cat and its weight is 4
Garfield cat 4
Pet(name='Pluto', animal='dog', weight=10)
Pluto is a dog and its weight is 10
Pluto dog 10