from enum import EnumMonth = 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 , 1Feb => Month.Feb , 2Mar => Month.Mar , 3Apr => Month.Apr , 4May => Month.May , 5Jun => Month.Jun , 6Jul => Month.Jul , 7Aug => Month.Aug , 8Sep => Month.Sep , 9Oct => Month.Oct , 10Nov => Month.Nov , 11Dec => 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 = 410 Fri = 511 Sat = 6