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 Check If a String Is a Number (Float)
Python List clear()
Python Operators
Python Program to Find the Size (Resolution) of a Image
Python Tuple index()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Program to Find Factorial of Number Using Recursion
Python id()
Python Program to Check if a Number is Positive, Negative or 0
Python format()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python memoryview()
Python Dictionary
Python Program to Print Hello world!
Python Data Structures and Algorithms - Benjamin Baka
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Debug a JavaMail Program
Python String endswith()
Python Operator Overloading
Python Program to Get the Class Name of an Instance
Python Global, Local and Nonlocal variables
Python abs()
Python str()
Python Set add()
Python timestamp to datetime and vice-versa
Python callable()
Python Program to Parse a String to a Float or Int
Python type()
Python Program to Check Armstrong Number
Python classmethod()
Python Function Arguments
Python Program to Find Armstrong Number in an Interval