🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Python Beginner

What is Enum?

A built-in class for creating enumerated constants — named groups of related values that improve code readability.

Enums replace magic numbers and strings with meaningful names: class Color(Enum): RED = 1; GREEN = 2; BLUE = 3. Access via Color.RED, Color(1), or Color['RED']. Members are iterable and comparable.

Specialized enums include IntEnum (integer-compatible), StrEnum (Python 3.11+, string-compatible), Flag (combinable with bitwise operators), and auto() for automatic value assignment. Enums make code more readable and prevent invalid values.

Related Terms

List Comprehension
A concise syntax for creating new lists by applying an expression to each item in an existing iterable.
Dataclass
A decorator that automatically generates __init__, __repr__, __eq__, and other special methods for classes that mainly store data.
Celery
A distributed task queue for Python that enables asynchronous processing of background jobs and scheduled tasks.
Python ABC Module
The Abstract Base Classes module that enables defining interfaces and abstract methods that subclasses must implement.
Context Manager
An object that manages resources by defining setup and cleanup actions using the with statement.
Python Packaging with Poetry
A modern dependency management and packaging tool for Python that simplifies project setup, versioning, and publishing.
View All Python Terms →