首页 > 代码库 > collectuions.namedtuple

collectuions.namedtuple

>>> import collections
>>> Sale=collections.namedtuple(‘Sale‘,‘price‘)
>>> sale1=Sale(‘98.7‘)
>>> print sale1.price,sale1[0]
98.7 98.7
>>> sale1._replace(price=100)
Sale(price=100)
>>> sale2=sale1._replace(price=100)
>>> sale1,sale2
(Sale(price=‘98.7‘), Sale(price=100))
>>> ‘{price}‘.format(**sale1._asdict())
‘98.7‘

#参考了 python3程序开发指南

collectuions.namedtuple