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 Sum of Natural Numbers
Python String split()
Python while Loop
Python Program to Add Two Numbers
Python zip()
Python del Statement
Python String title()
Deep Learning with Python - Francois Cholletf
Python bin()
Python List count()
Python Iterators
Python Program to Find Hash of File
Python any()
Python filter()
Python Program to Convert String to Datetime
Python Program to Safely Create a Nested Directory
Python Program to Create a Long Multiline String
Python Object Oriented Programming
Python Program to Find HCF or GCD
Python List index()
Python Program to Access Index of a List Using for Loop
Python isinstance()
Python range()
Python property()
Python String isprintable()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Print Output Without a Newline
Python String replace()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Find the Factors of a Number
Python String casefold()