0Pricing
Python Academy · Lesson

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

  1. The Enum Class
  2. IntEnum and Flag
  3. NamedTuple Basics
  4. typing.NamedTuple
← Back to Python Academy