首页 > 代码库 > 命名元组nametuple

命名元组nametuple

# coding:utf-8

from collections import namedtuple

Student = namedtuple(‘Student‘, [‘no‘, ‘name‘, ‘age‘, ‘sex‘])
student = Student("2016214338", u"张三", 19, u"")
print student.name
print student.age

-----结果显示--------------------

张三
19

 

命名元组nametuple