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 List append()
Python Program to Safely Create a Nested Directory
Python tuple()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Copy a File
Python String startswith()
Python Machine Learning - Sebastian Raschka
Python String rpartition()
Python pass statement
APIs in Node.js vs Python - A Comparison
Python String istitle()
Python Program to Find Sum of Natural Numbers Using Recursion
Python list()
Python Program to Count the Occurrence of an Item in a List
Python Dictionary keys()
Python Program to Remove Duplicate Element From a List
Python Program Read a File Line by Line Into a List
Python getattr()
Python Exception Handling Using try, except and finally statement
Python Program to Make a Simple Calculator
Python Program to Trim Whitespace From a String
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Check If Two Strings are Anagram
Python File I/O Operation
Deep Learning in Python - LazyProgrammer
Python Set add()
Python String maketrans()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String isupper()
Python Program to Print Hello world!
Python Keywords and Identifiers
Python timestamp to datetime and vice-versa