7 lines
289 B
Text
7 lines
289 B
Text
collections.namedtuple是一个工厂函数,可以用来构建一个带字段名的元组和一个有名字的类。
|
||
|
||
from collections import namedtuple
|
||
|
||
City = namedtuple('City', 'name country population coordinates')
|
||
beijing = City('Beijing', 'CN', 2700, (116.3, 39.9))
|
||
print(beijing)
|