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 Machine Learning - Sebastian Raschka
Python Input, Output and Import
Python bin()
Debug a JavaMail Program
Python strftime()
Python Dictionary pop()
Python String rfind()
Python File I/O Operation
Python Program to Display Calendar
Python hash()
Python Program to Compute all the Permutation of the String
Python String partition()
Python Program to Get the Full Path of the Current Working Directory
Python frozenset()
Python String find()
Python Program to Check If a List is Empty
Python classmethod()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python String endswith()
Python String isprintable()
Python String replace()
Python Program to Concatenate Two Lists
Python String swapcase()
Python Program to Convert Kilometers to Miles
Python Program to Differentiate Between del, remove, and pop on a List
Python Data Types
Python Program to Find the Sum of Natural Numbers
Python Dictionary setdefault()
Python String capitalize()
Python timestamp to datetime and vice-versa
Python Program to Find HCF or GCD
Python Generators