The OP clarified that their motivation is to use the enum value as an array index, which implies consecutive numbering starting from zero.
The documentation states:
The goal of the default [autonumbering] methods is to
provide the next int in sequence with the last int provided, but the
way it does this is an implementation detail and may change.
Hence it may be wise to define the autonumbering method explicitly, for example:
from enum import IntEnum, auto
class PrimaryColours(IntEnum):
def _generate_next_value_(name, start, count, last_values):
"""generate consecutive automatic numbers starting from zero"""
return count
RED = auto()
GREEN = auto()
BLUE = auto()
This will ensure that the enum
values are assigned consequtive values starting from zero:
print(PrimaryColours.RED.value,
PrimaryColours.GREEN.value,
PrimaryColours.BLUE.value)
> 0 1 2
Note that the value
property can be omitted if the context doesn't require it, e.g.:
orange = (255, 102, 0)
print(orange[PrimaryColours.GREEN])
> 102