
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Support for Enumerations in Python
In Python, Enumerations are implemented by using the enum module. The Enums has names and values. The Enums can be accessed by using names or values.
To use this module, we should import it using.
import enum
The Enum has some properties. These are −
- Enums can be displayed as string or repr format.
- The type() method can display the enum types
- There is name keyword, to show names of the enum members.
- Enums are iterable
Example Code
import enum class Rainbow(enum.Enum): VIOLET = 1 INDIGO = 2 BLUE = 3 GREEN = 4 YELLOW = 5 ORANGE = 6 RED = 7 print('The 3rd Color of Rainbow is: ' + str(Rainbow(3))) print('The number of orange color in rainbow is: ' + str(Rainbow['ORANGE'].value)) my_rainbow_green = Rainbow.GREEN print('The selected color {} and Value {}'.format(my_rainbow_green.name, my_rainbow_green.value))
Output
The 3rd Color of Rainbow is: Rainbow.BLUE The number of orange color in rainbow is: 6 The selected color GREEN and Value 4
- Related Articles
- enum - Support for enumerations in Python
- Python Support for gzip files (gzip)
- Python Support for bzip2 compression (bz2)
- Support for line-oriented command interpreters in Python\n
- Enumerations in Dart Programming
- How MySQL handles the empty and null values for enumerations?
- Constructor overloading in enumerations in Java.
- Python class browser support
- Does Python support polymorphism?
- HyperText Markup Language support in Python?
- Does Python support multiple inheritance?
- Memory-mapped file support in Python (mmap)?
- Does Java support default parameter values for a method?
- Personalization Strategies for Marketing, Sales, and Customer Support Teams
- Explain the ASP.NET Core support for multiple environments for development and production

Advertisements