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 range()
Python Keywords and Identifiers
Python set()
Python Dictionary keys()
Python Program to Sort Words in Alphabetic Order
Python Program to Sort a Dictionary by Value
Python bool()
Python int()
Python Program to Check if a Number is Positive, Negative or 0
Python str()
Python Program to Merge Mails
Python Program to Check the File Size
Python Program to Solve Quadratic Equation
Python Program to Check Whether a String is Palindrome or Not
Python String isspace()
Python String format()
Python Objects and Classes
Python Program to Print all Prime Numbers in an Interval
Python Set intersection()
Python Program to Add Two Numbers
Python Program to Convert String to Datetime
Python max()
Python isinstance()
Python String isalpha()
Python Directory and Files Management
Python Anonymous / Lambda Function
Python Program to Check if a Key is Already Present in a Dictionary
Python String ljust()
Python Program to Generate a Random Number
Python Program to Get the Class Name of an Instance
Python Set issuperset()
Node.js vs Python for Backend Development