IntEnum and Flag
Use integer and flag enums.
Beyond Plain Enum
The enum module ships specialized base classes. IntEnum members behave like integers, and Flag members can be combined with bitwise operators. They cover cases where plain Enum is too restrictive.
Plain Enum Is Not an int
A plain Enum member is not interchangeable with its integer value. Comparing it to a number returns False.
from enum import Enum
class Level(Enum):
LOW = 1
HIGH = 2
print(Level.LOW == 1)All lessons in this course
- The Enum Class
- IntEnum and Flag
- NamedTuple Basics
- typing.NamedTuple