from collections
import namedtuple
# Each kind of nametuple is represented by its own class,
# created by using the nametuple() factory function
# The arguments are the name of the new class and a string
# containing the names of the elements
Person = namedtuple(
'Person',
'name age gender')
print 'Type of Person:', type(Person)
bob = Person(name=
'Bob', age=30, gender=
'male')
print '\nRepresentation:', bob
jane = Person(name=
'Jane', age=29, gender=
'female')
print '\nField by name:', jane.name
print '\nField by index:'
for p
in [bob, jane]:
print '%s is a %d year old %s' % p
转载于:https://www.cnblogs.com/Shinered/p/9678797.html
相关资源:JAVA上百实例源码以及开源项目
转载请注明原文地址: https://mac.8miu.com/read-4838.html