1. 程式人生 > >python namedtuple命名元組

python namedtuple命名元組

from collections import namedtuple
Animal=namedtuple('Animal','name age type')
perry=Animal(name='perry',age=1,type='cat')
print(perry.type)
print(perry[0])
print(perry._asdict())