How can I represent an 'Enum' in Python?
Ask by Erick Wilsom
Updated 19 Jun 2023
Sure, here are the steps on how to represent an 'Enum' in Python:
Enumclass from theenummodule.Enumclass.Here is an example of how to represent an 'Enum' in Python:
Python
This code defines an enumeration called
Colorwith three members:RED,GREEN, andBLUE. The values of the members are 1, 2, and 3, respectively.Here is how you can use the
Colorenumeration:Python
The first line of code creates a variable called
colorand assigns it the valueColor.RED. The second line of code prints the value ofcolor. The third line of code prints the value of thevalueattribute ofcolor.