Armin Mesicpersonal blog

Rather than using just plaintuplesand wondering what each of the values means, we can usenamedtuples. It’s an easy way to selfdocument your code

from collections import namedtuple

Person = namedtuple('Person', ['Name', 'Job'])

bob_ross = Person("Bob Ross", "Painter")

print(bob_ross)
# Person(Name='Bob Ross', Job='Painter')

vs normaltuples

 bob_ross = ("Bob Ross", "Painer")
print(bob_ross)
# ('Bob Ross', 'Painer')