Enumerations of fixed values#
Python supports enumerations as of Python 3.4; an enumeration is a handy way to identify some distinct values that are important. Here’s an example where we enumerate flavors of milkshave:
Notice that Milkshake
subclasses Enum
(which we imported from enums
). The Milkshake
class itself is iterable, which is very convenient for when you have a finite set of options. Python gives us a nice way to access the name and value of an enumerated item, and gives us a good notion of equality.