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 Hash of File
Python abs()
Python Program to Differentiate Between del, remove, and pop on a List
Python Tuple index()
Python delattr()
Python round()
APIs in Node.js vs Python - A Comparison
Python Set difference()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Get a Substring of a String
Python sleep()
Python Program to Concatenate Two Lists
Python break and continue
Python Program to Check if a Number is Odd or Even
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python sorted()
Python type()
Python filter()
Python Set clear()
Python Program to Extract Extension From the File Name
Python Program to Print the Fibonacci sequence
Python Program to Return Multiple Values From a Function
Python Set copy()
Python timestamp to datetime and vice-versa
Python max()
How to get current date and time in Python?
Python Program to Print all Prime Numbers in an Interval
Python String isupper()
Python setattr()
Python Program to Get Line Count of a File
Debug a JavaMail Program
Python List copy()