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 a Python while loop with a condition gate controlling repeated execution
Python

Python While Loop: Syntax, Usage, and Common Pitfalls

python while loop: Understand the Python while loop: syntax, termination conditions, common mistakes, performance considerations, and when to choose alternatives like...

while loopPython loopsloop controliteration
Illustration of a Python for loop iterating over a list with a counter.
Python

Python for Loop: Syntax, Iteration, and Performance

Understand Python for loop syntax and iteration patterns, including range, enumerate, zip, control flow, and performance considerations.

Pythonfor loopiterationrange
Python match case pattern matching illustration with branching paths and a highlighted matching branch
Python

Python Match Case and Structural Pattern Matching: Syntax Guide

Practical guide to Python's match case and structural pattern matching: literal, sequence, mapping, guard, and class patterns, plus when to use them over if/elif.

pattern matchingmatch casePython 3.10control flow
Illustration of Python match case class pattern showing an object being matched against a class structure with attribute extraction.
Python

Python Match Case Class Pattern

python match case class pattern: Learn how to use Python's match statement with class patterns to match on type and attributes, capture values, and write readable cond...

structural pattern matchingclass patternsPython syntaxmatch statement
Illustration of Python match-case mapping pattern matching a dictionary structure.
Python

Python Match Case Mapping Pattern: Dictionary Matching

Learn how to use Python's mapping pattern in match statements: match dictionaries by structure, extract values, and write dispatch logic for dictionary-shaped input. Covers missing keys, extra keys, captures, guards, and common pitfalls.

structural pattern matchingdictionary dispatchmatch statementpython 3.10
Illustration of Python match case sequence pattern matching a list structure
Python

Python Match Case Sequence Pattern: Lists and Tuples

python match case sequence pattern: Learn how to use Python's match case sequence pattern to match lists, tuples, and other sequences with clear examples and common pi...

structural pattern matchingmatch statementsequence patternsPython 3.10
Illustration of Python match-case with a guard condition filtering patterns
Python

Python Match Case Guard: Conditional Pattern Filtering

python match case guard: Learn how to use guard clauses in Python's match-case to filter patterns with conditions, with practical examples and common pitfalls.

pattern matchingmatch statementguard clausesPython 3.10
Illustration of Python's match statement combining multiple patterns with the OR operator into a single case
Python

Python Match Case Multiple Patterns Explained

Learn how to combine multiple patterns in a single Python match case with the | operator, covering literals, structural patterns, guards, and edge cases.

pattern matchingstructural pattern matchingpython syntaxcontrol flow
Illustration of a Python match statement with a wildcard pattern matching multiple shapes, representing flexible pattern matching.
Python

Python Match Case Wildcard: Using _ and as Patterns

Understand Python match case wildcard patterns: `_` matches anything, `as` captures it, and case order decides which pattern wins.

PythonPattern MatchingMatch StatementWildcard
Illustration of a Python match statement with a default wildcard case catching unmatched values.
Python

Python Match Case Default: Using the Wildcard Pattern

Learn how the default case in Python's match statement works, how to use the wildcard pattern, and avoid common pitfalls when handling unmatched values.

pattern matchingmatch statementwildcard patterndefault case