September 2026
1051 pages
35h 4m
English
Python 3.6 introduced the Flag enumeration type, which defines the internal values so that the symbolic constants can be combined using bitwise operators. This is illustrated by the following example, in which the state of a traffic light system is represented by a combination of symbolic constants:
>>> class TrafficLight(enum.Flag):... Red = enum.auto()... Amber = enum.auto()... Green = enum.auto()...
With the help of the bitwise OR, two symbolic constants, also referred to as flags, can be combined:
>>> combined_state = TrafficLight.Red | TrafficLight.Amber
In our example, combined_state would describe a traffic light where the red and amber lights are currently on together.
The bitwise AND ...
Read now
Unlock full access