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 match statement with branching paths representing pattern matching cases
Python

Python Structural Pattern Matching Explained

Python structural pattern matching lets you write case-based code that destructures data and binds variables. This guide covers match syntax, guards, mappings, classes, and common pitfalls.

pattern matchingmatch statementcontrol flowPython 3.10
Illustration of Python's match statement routing data through multiple pattern branches
Python

Python Match Statement: Structural Pattern Matching

Learn how Python's match statement implements structural pattern matching: literal, capture, sequence, mapping, and class patterns, plus guards and common edge cases.

pythonstructural pattern matchingpython 3.10control flow
Illustration of Python structural pattern matching with match case branches leading to different outcomes.
Python

Python match case: Structural Pattern Matching

python match case: Learn Python match case for structural pattern matching: syntax, patterns, guards, common pitfalls, and when to prefer it over if-elif.

structural pattern matchingPython 3.10control flowpattern matching
A visual comparison of Python if statement and ternary operator syntax, showing two code paths.
Python

Python If Statement vs Ternary Operator

Learn the practical differences between Python if statements and ternary conditional expressions: syntax, readability, side effects, evaluation order, and when to choose each.

PythonConditional ExpressionsCode ReadabilityTernary Operator
Illustration of nested ternary conditional expressions in Python showing branching logic and readability tradeoffs.
Python

Python Nested Ternary: Syntax, Readability, and Alternatives

Learn how Python evaluates nested ternary expressions, when they improve clarity, and when if/elif/else chains or dictionaries are better alternatives.

pythonternary-operatorconditional-expressionscode-readability
Illustration of a Python ternary expression as a fork in a road with two branches and a condition symbol.
Python

Python Ternary Expression: Syntax and Usage

Learn how to use Python's ternary conditional expression for concise assignments, understand its syntax, and avoid common pitfalls.

Pythonconditional expressionternary operatorcode readability
Diagram showing a Python conditional expression with a condition in the middle and two value branches.
Python

Python Ternary Operator: Syntax and Practical Use

Learn how to use Python's conditional expression (the ternary operator) for concise value selection, including syntax, common mistakes, and when a regular if-else is clearer.

pythonconditional expressionsyntaxcode readability
Abstract illustration of a Python conditional expression showing a binary decision path between two values.
Python

Python Conditional Expression: Syntax and Use Cases

Learn the Python conditional expression (ternary operator) syntax, how it differs from if-else statements, and when to use it for cleaner, more readable code.

conditional-expressionternary-operatorpython-syntaxcode-readability
Illustration of a Python ternary operator with two branches and a condition, representing the inline if expression.
Python

Python Inline If: Syntax and Usage

Learn the syntax and practical uses of Python's inline if (ternary operator), including common mistakes and when to prefer a regular if-else.

pythonternary operatorconditional expressioncode readability
Illustration of a Python if statement with a not condition showing boolean negation.
Python

Using `not` in Python Conditions: Syntax and Common Pitfalls

Learn how to use the Python `not` operator in conditions, including truthiness, precedence, and common mistakes.

pythonboolean logicconditional statementstruthiness