Python has strong support for enumerated types.
For example, after importing Enum, I easily created an enumeration object for colours and weekdays:
>>> from enum import Enum
>>> Colours = Enum('red', 'blue', 'green')
>>> Weekdays = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
The return value is an immutable sequence object with a corresponding value for each of the string arguments supplied. Each value is also available as an attribute named from the corresponding string argument.
Furthermore, every value from an enumeration exports its sequence index as an integer and can be coerced to a simple string that matches the original arguments used to create the enumeration.
Using enum, I was able to easily compare the different values of the enumerations. The values are constants that can be compared only with values from the same enumeration. Any comparison with other values results in Python's fallback comparisons being invoked.
For example, I compared pizza night, which was a Thursday, with the fifth weekday, which is Friday:
>>> pizza_night = Weekdays[4]
>>> pizza_night == Weekdays.fri
True
I also found it easy to compare a shirt colour to other colours in the enumeration:
>>> shirt_colour = Colours.green
>>> shirt_colour > Colours.red
True
>>> shirt_colour == "green"
False
Overall, enum proved to be a valuable tool for working with enumerations in Python.
Version 0.4.4: N/A