Enum Class in Python
Level 4152 keystrokes
This creates an enumeration using the Enum class. auto() automatically assigns sequential values to members.
Python code
# Import Enum base class and auto function1from enum import Enum, auto2 # Define enumeration class inheriting from Enum3class Color(Enum): # auto() assigns value 14 RED = auto() # auto() assigns value 25 GREEN = auto() # auto() assigns value 36 BLUE = auto()7 # Print the enum member: Color.RED8print(Color.RED)# Print the name attribute: RED9print(Color.RED.name)# Print the value attribute: 110print(Color.RED.value)Output
Color.RED RED 1
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
(× 7)× 7.× 5=× 3,× 1:× 1