Python enum Module
Example
Define an enumeration and access its members:
from enum import Enum
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
print(Color.RED.name)
print(Color.RED.value)
Try it Yourself »
Definition and Usage
The enum module supports enumerations, which are sets of symbolic names bound to unique, constant values.
Use it to define readable constants, compare by identity, and iterate over named values cleanly.
Members
Member | Description |
---|---|
auto() | Automatically assign increasing values to enum members. |
Enum | Base class for creating simple enumerations. |
EnumType | Metaclass for Enum and Flag types. |
Flag | Base class for flag enumerations supporting bitwise operations. |
FlagBoundary | Controls behavior of invalid/combined Flag values. |
IntEnum | Enum where members are also (and must be) ints. |
IntFlag | Flag where members are also ints. |
StrEnum | Enum where members are also strings. |
unique() | Decorator that ensures all enumeration values are unique. |