---
title: "How can I represent an 'Enum' in Python?"  
description: "How can I represent an 'Enum' in Python?"  
author: "Erick Wilsom"  
published: 2022-10-27  
updated: 2023-06-19  
canonical: https://www.mindstick.com/forum/157172/how-can-i-represent-an-enum-in-python  
category: "python"  
tags: ["python", "python-3.x"]  
reading_time: 1 minute  

---

# How can I represent an 'Enum' in Python?

How can I represent the equivalent of an [Enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum) in [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)?

## Replies

### Reply by Aryan Kumar

Sure, here are the steps on how to represent an 'Enum' in Python:

1. Import the `Enum` class from the `enum` module.
2. Create a class that inherits from the `Enum` class.
3. Define the members of the enumeration as attributes of the class.
4. Optionally, you can define the values of the members of the enumeration.

Here is an example of how to represent an 'Enum' in Python:

Python

```plaintext
from enum import Enum

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

This code defines an enumeration called `Color` with three members: `RED`, `GREEN`, and `BLUE`. The values of the members are 1, 2, and 3, respectively.

Here is how you can use the `Color` enumeration:

Python

```plaintext
color = Color.RED

print(color)
# Color.RED

print(color.value)
# 1
```

The first line of code creates a variable called `color` and assigns it the value `Color.RED`. The second line of code prints the value of `color`. The third line of code prints the value of the `value` attribute of `color`.


---

Original Source: https://www.mindstick.com/forum/157172/how-can-i-represent-an-enum-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
