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:
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Tuple index()
Python Program to Delete an Element From a Dictionary
Python Program to Find the Size (Resolution) of a Image
Python Dictionary copy()
Python help()
Python Program to Find HCF or GCD
Python Global, Local and Nonlocal variables
Python String center()
Python RegEx
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Dictionary fromkeys()
Python String rjust()
Python String join()
How to Get Started With Python?
Python Errors and Built-in Exceptions
Python Program to Return Multiple Values From a Function
Python String islower()
APIs in Node.js vs Python - A Comparison
Python Program Read a File Line by Line Into a List
Python exec()
Python Set union()
Python if...else Statement
Python Program to Count the Number of Each Vowel
Python Closures
Python del Statement
Python Program to Check If Two Strings are Anagram
Python divmod()
Python complex()
Python Program to Create Pyramid Patterns
Python Program to Find Numbers Divisible by Another Number