定義枚舉類型
NAME, AGE, GENDER, EMAIL = xrang(4)
用標(biāo)準庫中的collections.namedtuple替代內(nèi)置tuple
from collections import namedtuple
# 定義tuple的名稱
Student = namedtuple('Student',['name','age','gender','email'])
# 賦值
s = Student('Jim',16,'male','example@example.com')
# 也可以命名賦值
s2 = Student(name = 'jim', age = 16, gender = 'male', email = 'example@example.com')
# 使用
s.name
# 判斷類型
isinstance(s, tuple)