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 chr()
Python Closures
Python String title()
Python @property decorator
Python Program to Remove Duplicate Element From a List
Python list()
Python Program to Differentiate Between del, remove, and pop on a List
Python Program to Find Hash of File
Python Program to Count the Number of Each Vowel
Python Program to Capitalize the First Character of a String
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python sum()
Python Program to Get the Full Path of the Current Working Directory
Python Program to Concatenate Two Lists
Python oct()
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Display Powers of 2 Using Anonymous Function
Python Tuple
Python dir()
Python String capitalize()
Python Dictionary update()
Python locals()
Python Program to Find the Square Root
Python Program to Check Armstrong Number
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Iterators
Python List insert()
Python eval()
Deep Learning with Python - Francois Chollet
Python Program to Get the Last Element of the List
Python Set update()
Python String join()