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 Swap Two Variables
Python strftime()
Python all()
Python bool()
Python eval()
Python type()
Python Program to Count the Number of Each Vowel
Python List reverse()
Python bytearray()
Python Program to Count the Occurrence of an Item in a List
Python open()
Python Program to Display Powers of 2 Using Anonymous Function
Python delattr()
Python del Statement
Python Strings
Python Dictionary copy()
Python String zfill()
Python Errors and Built-in Exceptions
Python chr()
Python vars()
Python divmod()
Python Global, Local and Nonlocal variables
Python strptime()
Python String find()
Python Program to Check If a String Is a Number (Float)
Python input()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Dictionary popitem()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python if...else Statement
Python String ljust()
Python slice()