标签:
Enum
可以把一组相关常量定义在一个class中,且class不可变,而且成员可以直接比较。
from enum import Enum Month = Enum(‘Month‘, (‘Jan‘, ‘Feb‘, ‘Mar‘, ‘Apr‘, ‘May‘, ‘Jun‘, ‘Jul‘, ‘Aug‘, ‘Sep‘, ‘Oct‘, ‘Nov‘, ‘Dec‘)) for name, member in Month.__members__.items(): print("%s => %s, %d" % (name, member, member.value))
>>> Jan => Month.Jan, 1 Feb => Month.Feb, 2 Mar => Month.Mar, 3 Apr => Month.Apr, 4 May => Month.May, 5 Jun => Month.Jun, 6 Jul => Month.Jul, 7 Aug => Month.Aug, 8 Sep => Month.Sep, 9 Oct => Month.Oct, 10 Nov => Month.Nov, 11 Dec => Month.Dec, 12
标签:
原文地址:http://www.cnblogs.com/roronoa-sqd/p/4900427.html