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 upper()
Intelligent Projects Using Python - Santanu Pattanayak
Python Strings
Python max()
Python strftime()
Python String isprintable()
Python Program Read a File Line by Line Into a List
Python Program to Count the Number of Occurrence of a Character in String
Python String isidentifier()
Python Operator Overloading
Python Set copy()
Python Program to Get File Creation and Modification Date
Python Set clear()
Python vars()
Python Program to Solve Quadratic Equation
Python Errors and Built-in Exceptions
Python Program to Extract Extension From the File Name
Python Program to Find the Largest Among Three Numbers
Python compile()
Python ascii()
Python String find()
Python setattr()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Set pop()
Python Decorators
Python String replace()
Python Program to Add Two Matrices
Python Deep Learning Cookbook - Indra den Bakker
Python pow()
Python Program to Get the Full Path of the Current Working Directory
Python sum()
Python str()