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 Set difference_update()
Python Set difference()
Python zip()
Python Operator Overloading
Python Program to Sort a Dictionary by Value
Python String title()
Python Program to Find Numbers Divisible by Another Number
Python all()
Python Program to Differentiate Between type() and isinstance()
Python while Loop
Python Program to Trim Whitespace From a String
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python String lower()
Python Program to Check Armstrong Number
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python List remove()
Python Program to Print all Prime Numbers in an Interval
Python Program to Count the Number of Digits Present In a Number
Python Anonymous / Lambda Function
Python String rpartition()
Python String swapcase()
Python String casefold()
How to Get Started With Python?
Python Dictionary fromkeys()
Python time Module
Python Program Read a File Line by Line Into a List
Python Program to Find the Size (Resolution) of a Image
Introduction to Scientific Programming with Python - Joakim Sundnes
Python any()
Python Set issuperset()
Python Dictionary update()