create a named tuple python

Solutions on MaxInterview for create a named tuple python by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "create a named tuple python"
Roberta
06 Aug 2019
1>>> from collections import namedtuple
2>>> Person = namedtuple('Person', 'first_name last_name zip_code')
3>>> p1 = Person('Joe', 'Schmoe', '93002')
4>>> p1.first_name
5'Joe'
6>>> p1[0]
7'Joe'
8>>> p1.zip_code
9'92002'
10>>> len(p1)
113
12>>> type(p1)
13<class '__main__.Person'>
14>>>