First you need to install the module enum34
pip install enum34
from enum import Enum
class Color(Enum):
red =1
green =2
blue =3
How to get enumerated values :
print(Color.red)
Input :Color.red , Directly use enumeration attribute values to get values
print(Color(1))
Output :Color.red, Use index values
print(Color[‘green’])
Output :Color.green , Use enumeration name index
x = [c for c in Color]
print(x)
Output : [<Color.red: 1>, <Color.green: 2>, <Color.blue: 3>]