Pages

Topics

Tools

↑↓navigate↵openescclose

Python guides

Every published Python guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Python guides

Illustration of Python delattr removing an attribute from an object, showing dynamic attribute deletion.
Python

Python delattr: How to Delete Attributes at Runtime

python delattr: Learn how to use Python's delattr() to remove attributes from objects dynamically, handle missing attributes, and understand interactions with properti...

PythonAttribute DeletionDynamic AttributesObject Introspection
Illustration of Python hasattr checking whether an object contains an attribute, shown as a magnifying glass over a Python object diagram.
Python

Python hasattr: Checking Object Attributes

Learn how Python's hasattr() checks object attributes, handles exceptions, and when to prefer getattr() or try/except.

hasattrPython builtinsattribute checkingduck typing
Illustration of Python setattr assigning a dynamic attribute to an object
Python

Using Python setattr for Dynamic Attribute Assignment

Learn how Python's setattr works, when to use it for dynamic attribute assignment, and common pitfalls to avoid.

setattrdynamic attributespython builtinsobject introspection
Illustration of Python getattr function retrieving an attribute with a default value from an object.
Python

Using Python getattr for Safe Dynamic Attribute Access

Access object attributes safely with Python's built-in getattr(), set fallback defaults, and avoid AttributeError in dynamic or data-driven code.

getattrdynamic attribute accessPython builtinsattribute handling
Illustration of the Python next() function retrieving items from an iterator with a default value fallback.
Python

Python next() Function: Usage and Error Handling

Learn how Python's next() function retrieves items from iterators, handles StopIteration, and uses default values in practical code.

Pythoniteratorsgeneratorsbuilt-in functions
Illustration of Python iter() function converting an iterable into an iterator for sequential access.
Python

Python iter() Function: Syntax and Usage

Understand Python's iter() function: how it creates iterators, the two-argument form, and practical use cases for manual iteration.

iteratorsiterablesnext()python builtins
Illustration of a Python string with curly braces and a formatted value, representing the format function.
Python

Using the Python format() Method for String Formatting

Learn how Python's format() method works: placeholders, format specifiers, alignment, number formatting, object and dictionary access, and choosing it over f-strings.

pythonstring formattingformat specifiersf-strings
Illustration of Python hex function converting an integer to a hexadecimal string with 0x prefix.
Python

Python hex Function: Syntax, Behavior, and Examples

python hex function: Learn how Python's hex() built-in converts integers to hexadecimal strings, including handling negative numbers, formatting options, and common pi...

hexinteger conversionbuilt-in functionsstring formatting
Diagram showing an integer value being converted to an octal string with a 0o prefix by Python's oct() function
Python

Python oct() Function: Syntax and Behavior

Learn how Python's oct() converts integers to octal strings, which inputs it accepts, how the 0o prefix works, and when to use format() instead.

oct functionbuilt-in functionsinteger conversionnumber formatting
Illustration of the Python bin() function converting an integer into its binary string representation with the 0b prefix.
Python

Python bin() Function: Converting Integers to Binary

Python's bin() function converts integers to binary strings with a 0b prefix. See how it handles negative values, accepts __index__ objects, and compares with format().

bin()Python built-insbit manipulationbinary conversion