Python Program to Represent enum – 2024

Hey guys, in this blog we will see a Python Program to Represent enum.

Code

from enum import Enum

class Day(Enum):
    JANUARY = 1
    FEBRUARY = 2
    MARCH = 3

# print the enum member
print(Day.FEBRUARY)

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

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

Output

Day.FEBRUARY
FEBRUARY
2
  • Here we have used enum.ENUM to create a Day class.
  • Day.FEBRUARY will give Day.FEBRUARY as the output.
  • Day.FEBRUARY.name will give FEBRUARY as the output.
  • Day.FEBRUARY.value will give 2 as the output.

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 514

Leave a Reply

Your email address will not be published. Required fields are marked *