[[Python]] `from enum import Enum` https://docs.python.org/3/library/enum.html#module-enum >An enumeration: >- is a set of symbolic names (members) bound to unique values >- can be iterated over to return its canonical (i.e. non-alias) members in definition order >- uses _call_ syntax to return members by value >- uses _index_ syntax to return members by name ==tldr==: an enum is like a special list of unique and ordered things The members of an Enum can be various types. For strings, `StringEnum`, for ints, `IntEnum` ## defining enums ### class syntax ```python class Color(Enum): RED = 1 GREEN = 2 BLUE = 3 ``` ### functional syntax ```python Color = Enum('Color', ['RED', 'GREEN', 'BLUE']) ``` ## using enums `Color['RED']` and `Color(1)` will both get you the same object, `<Color.RED: 1>` `Color.RED.name` = "RED", `Color.RED.value` = 1.