Google News
logo
Python Program to Represent enum
You can use the built-in `enum` module in Python to represent enumerations. Here's an example code that demonstrates how to use the `enum` module to define and use enumerations :
Program :
from enum import Enum

class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3

print(Color.RED)
print(Color.GREEN)
print(Color.BLUE)
Output :
Color.RED
Color.GREEN
Color.BLUE
In this code, we first import the `Enum` class from the `enum` module. Then, we define an enumeration called `Color` by creating a class that inherits from `Enum`.

Inside the `Color` class, we define three enumeration members: `RED`, `GREEN`, and `BLUE`. Each member is assigned a unique integer value.

Finally, we print out each enumeration member using the `print()` function.

This code demonstrates how to define an enumeration and access its members. You can also use enumerations in switch-case statements and loops, just like any other data type.