1、
from collections import namedtuple
City=namedtuple('City','name country population coordinates')
City._fields #类属性
Out[17]: ('name', 'country', 'population', 'coordinates')
Latlong = namedtuple('Latlong','Lat Long')
beijing=('Beijing','China',2200,Latlong(40,120))
City._make(beijing) #类方法 相当于City(*beijing)
Out[20]: City(name='Beijing', country='China', population=2200, coordinates=Latlong(Lat=40, Long=120))
Beijing=City._make(beijing)
Beijing._asdict() #实例方法
Out[22]:
OrderedDict([('name', 'Beijing'),
('country', 'China'),
('population', 2200),
('coordinates', Latlong(Lat=40, Long=120))])
2、除了增减元素之外,元组支持列表其他所有方法。