Enum
Enumerations (enums) are a way to define a set of symbolic names bound to unique, constant values. Python's `enum` module provides a robust implementation with support for integer and string compatibility. The guide walks through Enum Basics, auto() & Aliases, IntEnum & StrEnum, Flag & IntFlag, Methods & Customization. Define an enum by subclassing `Enum` and defining class attributes: `class Color(Enum): RED = 1; GREEN = 2`. Members have `.name` (the attribute name) and `.value` (the assigned value). Iterate over enums with `list(Color)` or `for c in Color:`. `auto()` automatically assigns sequential integer values starting from 1. Two members with the same value cause the second to become an alias of the first. Use `@unique` decorator to ensure no duplicate values. Aliases appear in `__members__` but not in iteration. `IntEnum` inherits from both `Enum` and `int`, enabling enum members to be used directly where integers are expected (comparison, arithmetic). `StrEnum` (Python 3.11+) provides string compatibility. Both enable seamless integration with existing code.