Skip to content

Instantly share code, notes, and snippets.

@filipwodnicki
Last active June 13, 2019 16:32
Show Gist options
  • Save filipwodnicki/a9674638fd8c3bc5f4c00a8a800bc3e6 to your computer and use it in GitHub Desktop.
Save filipwodnicki/a9674638fd8c3bc5f4c00a8a800bc3e6 to your computer and use it in GitHub Desktop.
How to use Named Tuples in Python
# source: https://pymotw.com/2/collections/namedtuple.html
# doc: https://docs.python.org/3.7/library/collections.html#collections.namedtuple
import collections
Person = collections.namedtuple('Person', field_names=['name', 'age', 'gender'])
filip = Person(name='Filip', age=101, gender='undisclosed')
print(filip.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment