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 String casefold()
Python compile()
Python Program to Compute the Power of a Number
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Remove Duplicate Element From a List
Python Program to Check Leap Year
Python bin()
Python String maketrans()
Python frozenset()
Python isinstance()
Python Program to Find Numbers Divisible by Another Number
Python for Loop
Python Set add()
Python Dictionary keys()
Python set()
Python List append()
Python Dictionary items()
Python Set difference()
Python Set symmetric_difference_update()
Python timestamp to datetime and vice-versa
Python Program to Delete an Element From a Dictionary
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Sort Words in Alphabetic Order
Python Program to Count the Occurrence of an Item in a List
Python Data Types
Python Dictionary setdefault()
Python tuple()
Python String ljust()
How to Get Started With Python?
Python String rfind()
Python round()
Python String replace()