In this example, you will learn 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.
Related posts:
Python Program to Find the Factors of a Number
Python eval()
Python Dictionary clear()
APIs in Node.js vs Python - A Comparison
Python Program to Differentiate Between type() and isinstance()
Python Program to Sort a Dictionary by Value
Python Program to Get Line Count of a File
Python timestamp to datetime and vice-versa
Python String ljust()
Python Program to Merge Mails
Python bytearray()
Python Dictionary popitem()
Python String isalpha()
Python String partition()
How to Get Started With Python?
Python for Loop
Python Program to Capitalize the First Character of a String
Python String center()
Python String rindex()
Python len()
Python String splitlines()
Python Program to Add Two Matrices
Python Program to Convert Kilometers to Miles
Python Program to Safely Create a Nested Directory
Python Program to Iterate Through Two Lists in Parallel
Python Deep Learning Cookbook - Indra den Bakker
Python Dictionary get()
Python Program to Find the Size (Resolution) of a Image
Python File I/O Operation
Python String translate()
Python Dictionary copy()
Python String startswith()