1import enum
2# Using enum class create enumerations
3class Days(enum.Enum):
4 Sun = 1
5 Mon = 2
6 Tue = 3
7# print the enum member as a string
8print ("The enum member as a string is : ",end="")
9print (Days.Mon)
10
11# print the enum member as a repr
12print ("he enum member as a repr is : ",end="")
13print (repr(Days.Sun))
14
15# Check type of enum member
16print ("The type of enum member is : ",end ="")
17print (type(Days.Mon))
18
19# print name of enum member
20print ("The name of enum member is : ",end ="")
21print (Days.Tue.name)
1>>> from enum import Enum
2>>> class Color(Enum):
3... RED = 1
4... GREEN = 2
5... BLUE = 3
6...
7
1import enum
2
3class Days(enum.Enum):
4 Sun = 1
5 Mon = 2
6 Tue = 3
7
8print ("The enum members are : ")
9
10for weekday in (Days):
11 print(weekday)
12
13# The enum members are :
14# Days.Sun
15# Days.Mon
16# Days.Tue
17
18best_day = Days.Sun
19worst_day = Days(2)
20
21print(best_day) # Days.Sun
22print(worst_day) # Days.Mon