Category: 5. Enumeration
-
Python enum auto
Summary: in this tutorial, you’ll learn about the enum auto() function to generate unique values for enumeration members. Introduction to the enum auto() function The following example defines an enumeration with three members whose values are 1, 2, and 3: In this example, we manually assign integer values to the members of the enumeration. To make it…
-
Customize and Extend Python Enum Class
Summary: in this tutorial, you’ll learn how to customize and extend the custom Python enum classes. Customize Python enum classes Python enumerations are classes. It means that you can add methods to them, or implement the dunder methods to customize their behaviors. The following example defines the PaymentStatus enumeration class: The PaymentStatus enumeration has three members: PENDING, COMPLETED, and REFUND. The following displays the…
-
Python Enum aliases & @enum.unique Decorator
Summary: in this tutorial, you’ll learn about enumeration member aliases and how to use the enum unique decorator to ensure the uniqueness of member values. Introduction to the enum aliases By definition, the enumeration member values are unique. However, you can create different member names with the same values. For example, the following defines the Color enumeration: In this…
-
Python Enumeration
Summary: in this tutorial, you’ll learn about Python enumeration and how to use it effectively. Introduction to the Python Enumeration By definition, an enumeration is a set of members that have associated unique constant values. Enumeration is often called enum. Python provides you with the enum module that contains the Enum type for defining new enumerations. And you define…