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

A visual metaphor of a recursive function as a spiral of nested call frames, each smaller than the last, with a base case at the center.
Python

Python Recursion: How It Works and When to Use It

Understand how recursion works in Python, including the call stack, recursion limits, common pitfalls, memoization, and when iteration is a better choice.

recursioncall stackmemoizationiteration
A visual metaphor of a python recursive function showing nested function calls and a stack
Python

Python Recursive Function: A Practical Guide

Learn how a Python recursive function works, when to use recursion, and how to avoid stack overflow and performance pitfalls.

recursionbase casestack overflowmemoization
Illustration of a Python function with a return type annotation, showing the arrow syntax and a type label.
Python

Python Return Type Hints: Syntax and Usage

Learn how to declare return type hints in Python, handle optional and union returns, and use typing constructs for cleaner, more maintainable code.

type hintstyping modulefunction annotationsstatic type checking
Illustration of a Python function signature with parameter type hints and a magnifying glass symbolizing static analysis
Python

Python Parameter Type Hints: Syntax and Runtime Behavior

Understand Python parameter type hints: syntax, runtime behavior, and how they improve code maintainability and static analysis.

type hintstyping modulefunction annotationsstatic analysis
Illustration showing a Python function signature with type annotations attached to parameters and return value.
Python

Python Function Annotations: Syntax and Practical Use

Learn how Python function annotations work, what they do at runtime, and how to use them with type checkers and frameworks like FastAPI.

type hintstypingmypystatic type checking
Illustration of a Python dictionary being passed into a function, with a copy and reference concept.
Python

Passing a Dictionary to a Python Function: Syntax and Behavior

Learn how passing a dictionary to a Python function works, including reference vs copy semantics, **kwargs expansion, and avoiding mutable default pitfalls.

function argumentsdictionarykwargsmutable defaults
Illustration of a Python list being passed into a function, with a shared reference and mutation side effects highlighted
Python

Python Pass List to Function: Behavior and Pitfalls

Learn how Python passes lists to functions, why in-place changes affect the caller, and how to avoid mutable default arguments.

PythonFunction ArgumentsList MutationPass by Reference
Illustration of Python function call with arguments being unpacked from a list and dictionary into a function signature.
Python

Python Argument Unpacking: *args and **kwargs

Learn how Python argument unpacking works with *args and **kwargs, including sequence and mapping unpacking, function definitions, common errors, and performance trade-offs.

PythonFunction Arguments*args**kwargs
Illustration of a Python function signature with *args and **kwargs parameters, showing the separation of positional and keyword arguments.
Python

Python Args Kwargs Together: Syntax and Usage

Learn how to combine *args and **kwargs in Python function definitions, including ordering rules, unpacking, and practical examples.

Python*args**kwargsFunction Arguments
Diagram showing *args collecting positional arguments into a tuple and **kwargs collecting keyword arguments into a dictionary.
Python

Python args kwargs difference: *args vs **kwargs

python args kwargs difference: Learn how *args and **kwargs differ in Python: *args collects positional arguments into a tuple, **kwargs collects keyword arguments int...

*args**kwargsfunction parametersargument unpacking