python 面向对象十三 枚举类

2018-06-18 00:00:22来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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(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
 1 from enum import Enum, unique
 2 
 3 @unique
 4 class Weekday(Enum):
 5     Sun = 0 # Sun的value被设定为0
 6     Mon = 1
 7     Tue = 2
 8     Wed = 3
 9     Thu = 4
10     Fri = 5
11     Sat = 6

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:sklearn交叉验证-【老鱼学sklearn】

下一篇:python 面向对象十二 元类