Advertisement
rfmonk

collection_namedtuple_person.py

Jan 10th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import collections
  5.  
  6. Person = collections.namedtuple('Person', 'name age gender')
  7. print 'Type of Person:', type(Person)
  8.  
  9. bob = Person(name='Bob', age=30, gender='male')
  10. print '\nRepresentation:', bob
  11.  
  12. jane = Person(name='Jane', age=29, gender='female')
  13. print '\nField by name:', jane.name
  14.  
  15. print '\nFields by index:'
  16. for p in [bob, jane]:
  17.     print '%s is a %d year old %s' % p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement