命名元组
from collections import namedtuple Duck = namedtuple('Duck', 'bill tail') duck = Duck('wide orange', 'long') print(duck) #Duck(bill='wide orange', tail='long') print(duck.bill) #wide orange Duck2 = namedtuple('Duck2', 'bill tail') parts = {'bill': 'wide orange', 'tail': 'long'} print(Duck(**parts)) #Duck(bill='wide orange', tail='long') duck3 = duck._replace(tail='magnificent', bill='crushing') #命名元组不可变 替换其中某些域的值返回一个新的命名元组 print(duck3) #Duck(bill='crushing', tail='magnificent')