Enumerations are not built into Python, but the feature can be imported with the line
from enum import Enum
Enumerations are defined as in the following example:
class Answer(Enum):
YES = 'yes'
MAYBE = 'maybe'
MAYBE_NOT = 'maybe not'
NO = 'no'
Here the enumeration is called Answer
(enumeration names should be written in upper camelcase), it has
the four values Answer.YES
, Answer.MAYBE
, Answer.NO
, and
Answer.MAYBE_NOT
(enumeration value names should be written in all uppercase with words separated by
underscores), and each of those enumeration values has a string for its underlying value.
Underlying values are typically identifying numbers and strings, and are mostly used when combining Python with other programming languages. For example, C and C++ store enumeration values as integers, so Python must know their numeric codes to communicate them to C or C++ code.
Finish the enumeration so that it is called Direction
and has four enumeration values, one for each
cardinal direction, with lowercase direction names as the underlying values.