Browse by Topic

Popular

Latest

Latest Posts

Diagram showing Python StrEnum members connected to their string values, illustrating that enum members behave as strings
Python

Python StrEnum: String-Based Enums

Learn how Python 3.11's StrEnum creates string-based enums, simplifies serialization, and improves on the str, Enum mixin pattern.

StrEnumPython enumPython 3.11string serialization
Illustration of Python IntEnum combining integer and enum concepts, showing a gear with numeric values and named labels.
Python

Python IntEnum: Using Enumerations as Integers

python intenum: Learn how to use Python's IntEnum to combine integer behavior with enumeration safety, including comparisons, serialization, and common pitfalls.

IntEnumPython enumtype safetyserialization
Illustration of Python enum members being assigned sequential values automatically by the auto() function
Python

Using Python enum.auto() for Automatic Enum Values

Learn how Python's enum.auto() assigns values, how to customize the generation hook, and when explicit enum values are safer.

Enumauto()PythonCode Generation
Python enum module illustration showing symbolic constants as colored blocks
Python

Using Python Enum Module for Safer Code

The Python enum module lets you define symbolic constants, improve type safety, and simplify validation in your code.

EnumPythonType SafetyCode Quality
A Python enum class diagram showing named members with associated values, representing type-safe constants.
Python

Using Python Enum Class for Type-Safe Constants

Learn how to use Python's Enum class for type-safe constants: syntax, iteration, auto values, and common pitfalls.

PythonEnumType SafetyConstants
A diagram showing a Python enum class with named members and values, illustrating type safety and iteration.
Python

Python Enums: How to Use Enum and IntEnum

Learn how to define and work with Python enums: Enum, IntEnum, StrEnum, auto(), iteration, comparison, and type hints.

PythonEnumIntEnumType Safety
Diagram comparing Python object attribute storage: a dictionary on the left versus a compact slots layout on the right.
Python

python slots vs dict: Attribute Storage Compared

python slots vs dict: Understand how Python stores object attributes in a dict versus __slots__, and learn when to use each for memory and performance.

Python__slots__memory optimizationperformance
Diagram showing a Python instance with __slots__ replacing the instance dictionary to reduce memory footprint.
Python

Python Slots Memory Optimization: Reduce Instance Memory

Learn how Python's `__slots__` reduces per-instance memory, when to use it, and the tradeoffs with inheritance, dynamic attributes, and weak references.

__slots__memory optimizationPython performanceinstance attributes
Editorial illustration showing a compact slotted Python class object next to a bulky dictionary, highlighting memory savings
Python

Python Slots: Save Memory and Speed Up Attribute Access

Learn how Python's __slots__ removes the per-instance __dict__, when inheritance silently reintroduces it, and when slots are a good design choice.

__slots__memory optimizationPython classesperformance
A Python code editor showing a property setter with a validation check and an error message for an invalid value.
Python

Python Property Validation: Using @property Setters

See how @property setters are used for Python property validation, raise useful errors, and compare this approach with dataclasses and descriptors.

pythonpropertyvalidationsetter