Creating Enumerations With the Functional API
It can also take up to four optional and keyword-only arguments:
start. On screen is a table that summarizes the content and meaning of each argument in the signature of
type argument is required when you want to provide a mixin class for your enumeration. Using a mixin class can provide your custom
Enum with new functionality, such as extended comparison capabilities as you’ll learn later on in the course.
The reason for this default value is that zero is false in a Boolean sense, but
Enum members evaluate to true. Therefore, starting from zero would be a little inconsistent and potentially confusing.
04:10 Remember that this example is intended to show that the functional API is the way to go when you need to create enumerations dynamically. It’s not good programming practice because creating any object from user input is quite risky, considering that you can’t predict what they will input.
Providing a list of name-value tuples makes it possible to create the
HTTPStatusCode enumeration with custom values for the members. If you didn’t want to use a list of name-value tuples, then you could also use a dictionary that maps names to values.
Become a Member to join the conversation.