1.from collections import namedtuple
websites = [
('Sohu', 'http://www.google.com/', u'外围'),
('Sina', 'http://www.sina.com.cn/', u'损失'),
('163', 'http://www.163.com/', u'让人')
]
Website = namedtuple('Website', ['name', 'url', 'founder'])
for website in websites:
website = Website._make(website)
print (website)
2.Website = namedtuple('Website', ['name', 'url', 'founder'])
aa =Website( ('Sohu', 'http://www.google.com/', u'张朝阳'),
('Sina', 'http://www.sina.com.cn/', u'王志东'),
('163', 'http://www.163.com/', u'丁磊'))
print(aa)
Website(name=('Sohu', 'http://www.google.com/', '张朝阳'),
url=('Sina', 'http://www.sina.com.cn/', '王志东'),
founder=('163', 'http://www.163.com/', '丁磊'))
3.Website = namedtuple('Website', ['name', 'url', 'founder'])
aa =Website( name=(300, 300),url=21,founder=21)
print(aa)
from collections import namedtuple
最新推荐文章于 2023-10-29 15:52:01 发布