How can I represent the equivalent of an Enum in Python?
How can I represent an 'Enum' in Python?
37027-Oct-2022
Updated on 19-Jun-2023
Home / DeveloperSection / Forums / How can I represent an 'Enum' in Python?
How can I represent the equivalent of an Enum in Python?
Aryan Kumar
19-Jun-2023Sure, here are the steps on how to represent an 'Enum' in Python:
Enum
class from theenum
module.Enum
class.Here is an example of how to represent an 'Enum' in Python:
Python
This code defines an enumeration called
Color
with three members:RED
,GREEN
, andBLUE
. The values of the members are 1, 2, and 3, respectively.Here is how you can use the
Color
enumeration:Python
The first line of code creates a variable called
color
and assigns it the valueColor.RED
. The second line of code prints the value ofcolor
. The third line of code prints the value of thevalue
attribute ofcolor
.