Python Program to Represent enum

To understand this example, you should have the knowledge of the following Python programming topics:


Using enum module

from enum import Enum

class Day(Enum):
    MONDAY = 1
    TUESDAY = 2
    WEDNESDAY = 3

# print the enum member
print(Day.MONDAY)

# get the name of the enum member
print(Day.MONDAY.name)

# get the value of the enum member
print(Day.MONDAY.value)

Output

Day.MONDAY
MONDAY
1

Here, we have class Day with the object Enum as its argument. name and value are the attributes of Enum which give the name and value of the member MONDAY respectively.

You can refer to the official documentation of enum for more information.

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges