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