Named Tuples
- programmer can define their own type
- the new type has named attributes
from collections import namedtuple
def name_tuple_examples():
Person = namedtuple("Person", ['name', 'job', 'company', 'years'])
me = Person('Sharon', 'Professor', 'JMU', 14)
CS1 = Person('Sydney', 'Software Engineer', 'Verizon', 6)
CS2 = Person('Kathryn', 'Software Engineer', 'Epic', '2')
print(me)
print(CS1)
print(CS2)
print(f'{me.name}, {CS1[0]}, {CS2.name}')
print(type(me[3]), type(CS2[3]))
name_tuple_examples()