Build Enumerations of Constants With Python’s Enum
Python’s enum
module provides the Enum
class, which allows you to create enumeration types. To create your own enumerations, you can either subclass Enum
or use its functional API. Both options will let you define a set of related constants as enum members.
In the following sections, you’ll learn how to create enumerations in your code using the Enum
class. You’ll also learn how to set automatically generated values for your enums and how to create enumerations containing alias and unique values. To kick things off, you’ll start by learning how to create an enumeration by subclassing Enum
.
Creating Enumerations by Subclassing Enum
The enum
module defines a general-purpose enumeration type with iteration and comparison capabilities. You can use this