Gavin Wiggins

AboutNotesPhotos


Enumerations

Written on November 8, 2022

An enumeration is a set of symbolic names that are bound to unique, constant values. Enumerations (or enums) are implemented in Python using the Enum class from the enum module.

>>> from enum import Enum

>>> class Shape(Enum):
...     Triangle = 3
...     Square = 4
...     Pentagon = 5

>>> tri = Shape.Triangle

>>> tri.name
'Triangle'

>>> tri.value
3

Gavin Wiggins © 2024.
Made on a Mac with Genja. Hosted on GitHub Pages.