How can I represent an 'Enum' in Python?
How can I represent the equivalent of an Enum in Python?
Writing is my profession! I have written hundreds of article for many organizations and looking forward to work with growing organization. I am compatible to produce content in many categories including International politics, Healthcare, Education, Lifestyle, etc.. I understand the value of your time that you have invested to read my bio. #thanks
Aryan Kumar
19-Jun-2023Sure, 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.