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 Set update()
Python list()
Python String isnumeric()
Python Program to Differentiate Between del, remove, and pop on a List
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Dictionary pop()
Python hasattr()
Python Inheritance
Python String rstrip()
Python String isalpha()
Python Program to Get File Creation and Modification Date
Python Program to Find HCF or GCD
Python globals()
Python Operator Overloading
Python String encode()
Python isinstance()
How to Get Started With Python?
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python ord()
Python Sets
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python locals()
Python Get Current time
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Find the Square Root
Python Program to Check Whether a String is Palindrome or Not
Python Global, Local and Nonlocal variables
Python min()
Python Set pop()
Python Program to Create a Long Multiline String
Python Program to Get Line Count of a File