python enums code example
Example 1: enum in python
import enum
class Days(enum.Enum):
Sun = 1
Mon = 2
Tue = 3
print ("The enum member as a string is : ",end="")
print (Days.Mon)
print ("he enum member as a repr is : ",end="")
print (repr(Days.Sun))
print ("The type of enum member is : ",end ="")
print (type(Days.Mon))
print ("The name of enum member is : ",end ="")
print (Days.Tue.name)
Example 2: enum python
>>> from enum import Enum
>>> class Color(Enum):
... RED = 1
... GREEN = 2
... BLUE = 3
...
Example 3: get value from enum python
print(D.x.value)
Example 4: python enums
import enum
class Days(enum.Enum):
Sun = 1
Mon = 2
Tue = 3
print ("The enum members are : ")
for weekday in (Days):
print(weekday)
best_day = Days.Sun
worst_day = Days(2)
print(best_day)
print(worst_day)