In Python, enumeration is the same as the class variable we define in the object. Each class variable is an enumeration item. The way to access the enumeration item is: the class name plus the class variable.
class color():YELLOW = 1RED = 2GREEN=3PINK = 4# access enumeration itemsprint(color.YELLOW) # The output result is 1
Although this can solve the problem, it is not rigorous and not very safe, such as:
1. In the enumeration class, there should not be enumeration items (class variables) with the same key
2. It is not allowed to directly modify the value of the enumeration item outside the class
class color():YELLOW = 1YELLOW = 3 # Note that YELLOW is assigned 3 again, which will overwrite the previous 1RED = 2GREEN=3PINK = 4# access enumeration itemsprint(color.YELLOW) #3# But the value of the defined enum item can be modified externally, which should not happencolor.YELLOW = 99print(color.YELLOW) # 99