> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Enum

An enumeration (Enum) in Python is a data structure consisting of a set of bound, symbolic names (members) mapped to constant values. Implemented via the standard library's `enum` module, Enums are created by subclassing the `Enum` base class, providing a namespace where the members behave as immutable, iterable singletons.

```python theme={"dark"}
from enum import Enum

class Status(Enum):
    PENDING = 1
    ACTIVE = 2
    INACTIVE = 3
```

## Member Access and Attributes

Enum members can be accessed programmatically via three distinct mechanisms: by attribute, by value, or by name. Every member is an instance of its parent Enum class and exposes `.name` and `.value` properties.

```python theme={"dark"}

# Access by attribute
state = Status.ACTIVE


# Access by value (instantiation)
state = Status(2)


# Access by name (dictionary lookup)
state = Status['ACTIVE']


# Property resolution
print(state.name)   # Output: 'ACTIVE'
print(state.value)  # Output: 2
```

## Technical Characteristics

**Singleton Identity and Comparison**
Enum members are singletons in memory. They should be compared using the `is` operator for identity checks, though equality `==` is also supported. By default, standard `Enum` members do not evaluate as equal to their underlying values.

```python theme={"dark"}
Status.ACTIVE is Status.ACTIVE  # True
Status.ACTIVE == Status.ACTIVE  # True
Status.ACTIVE == 2              # False (Type mismatch: Status vs int)
```

**Immutability**
Once an Enum class is defined, its members and their corresponding values cannot be modified at runtime. Attempting to reassign a member (e.g., `Status.PENDING = 0`) raises an `AttributeError`.

**Iteration**
Enums natively support iteration. Iterating over the Enum class yields its members in the exact order they were defined.

```python theme={"dark"}
for state in Status:
    print(repr(state))

# <Status.PENDING: 1>

# <Status.ACTIVE: 2>

# <Status.INACTIVE: 3>
```

## Aliasing and the `@unique` Decorator

If multiple members in an Enum are assigned the same value, the first defined member becomes the primary member, and subsequent members become aliases. Aliases are excluded during standard iteration.

To strictly enforce value uniqueness at class creation time, Python provides the `@unique` decorator.

```python theme={"dark"}
from enum import Enum, unique

@unique
class ErrorCode(Enum):
    NOT_FOUND = 404
    MISSING = 404  # Raises ValueError: duplicate values found
```

## Automatic Value Generation

The `auto()` helper function automatically generates values for Enum members, delegating the exact value assignment to the `_generate_next_value_` method (which defaults to incrementing integers starting at 1).

```python theme={"dark"}
from enum import Enum, auto

class Signal(Enum):
    RED = auto()    # 1
    YELLOW = auto() # 2
    GREEN = auto()  # 3
```

## Specialized Enum Base Classes

Python provides specialized Enum variants to alter comparison behavior and support specific operations:

* **`IntEnum`**: Members are subclasses of both the Enum type and the built-in `int`. Unlike standard Enums, `IntEnum` members *can* be compared directly to integers and used in mathematical operations.

```python theme={"dark"}
from enum import IntEnum

class Priority(IntEnum):
    LOW = 1
    HIGH = 2

Priority.LOW == 1  # True
```

* **`Flag` and `IntFlag`**: Designed to support bitwise operations (`|`, `&`, `^`, `~`). Members can be combined to create complex, multi-state values.

```python theme={"dark"}
from enum import Flag, auto

class Permissions(Flag):
    READ = auto()    # 1
    WRITE = auto()   # 2
    EXECUTE = auto() # 4

# Bitwise OR combination
user_perms = Permissions.READ | Permissions.WRITE

# Bitwise AND check
has_read = bool(user_perms & Permissions.READ) # True
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
