June 2019
Beginner to intermediate
770 pages
19h 24m
English
The enum module provides the Enum class. One common use case for this class is to define an enumerated domain of values; for example, we might use this to enumerate the four suits for playing cards.
An enumerated type has the following two features:
In several previous examples, we've used a simplistic definition for the enumerated members. Here's a typical class definition:
from enum import Enumclass Suit(Enum): Clubs = "♣" Diamonds = "♦" Hearts = "♥" Spades = "♠"
This provides four members. We can use Suit.Clubs to reference a specific string. We can also use ...
Read now
Unlock full access