码迷,mamicode.com
首页 > 编程语言 > 详细

python 面向对象十三 枚举类

时间:2017-12-22 12:30:23      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:print   ems   pos   int   body   member   color   members   sep   

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

 

python 面向对象十三 枚举类

标签:print   ems   pos   int   body   member   color   members   sep   

原文地址:http://www.cnblogs.com/gundan/p/8085218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!