🎁 New User? Get 20% off your first purchase with code NEWUSER20 · ⚡ Instant download · 🔒 Secure checkout 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

Dataclass
A decorator that automatically generates __init__, __repr__, __eq__, and other special methods for classes that mainly store data.
Requests Library
An elegant HTTP library for Python that simplifies making web requests with a human-friendly API.
Magic Methods
Special double-underscore methods that define how Python objects behave with built-in operations and functions.
List Comprehension
A concise syntax for creating new lists by applying an expression to each item in an existing iterable.
Pickle
Python's built-in module for serializing and deserializing Python objects into a byte stream for storage or transmission.
Python Typing Module
A standard library module providing type hints for function signatures and variables, enabling static analysis without runtime enforcement.
View All Python Terms →