Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Named tuple (sort of immutable dictionary)

  • namedtuple

  • A bit like an immutable dictionary

from collections import namedtuple

Person = namedtuple('Person', ['name', 'email'])

one = Person(name='Joe', email='joe@example.com')
two = Person(name='Jane', email='jane@example.com')

print(one.name)
print(two.email)