🧩Enumeration (Enum)
Also known as Enum, Enumerated Type, Enums
A type with a short, fixed list of named choices, like RED, AMBER and GREEN.
Think of it like
It is like a menu with only three drinks. You must pick one of those, nothing else.
Example
Emma's order app has an enum with PAID, SHIPPED and DELIVERED. An order can only ever be one of the three.
Why it matters
Loose text like "shipped" and "Shipped" can slip through as two values. An enum allows exactly one spelling.
Definition
Example code
python
from enum import Enum
class Light(Enum):
RED = 1
AMBER = 2
GREEN = 3
print(Light.GREEN.name)
# GREENCommon mistake
Key takeaways
- 1Fixed choices. Only the listed names are allowed.
- 2Names, not numbers. The code says what it means.
- 3Typos caught. A wrong name is an error.