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 showing True and False as integer values 1 and 0, connected to the Python bool and int types.
Python

Python bool int Relationship: Subclass and Pitfalls

Understand how Python's bool, a subclass of int, affects truthiness, arithmetic, comparisons, and type checks, and learn to avoid common pitfalls.

boolinttype systemtruthiness
Illustration of a Python boolean conversion showing truthy and falsy values flowing into a bool() function
Python

Python Bool Conversion: Truthiness and bool()

Understand how Python converts values to booleans: truthiness rules, explicit bool() calls, string parsing gotchas, and common pitfalls.

bool()truthinesstype conversionPython idioms
Illustration of a Python object being evaluated as true or false in a boolean context, with a switch or scale metaphor.
Python

Python Truth Value Testing Explained

Learn how Python decides whether an object is true or false in boolean contexts, and how to define __bool__ and __len__ to control that behavior.

truthinessboolean context__bool____len__
Diagram showing Python truthy and falsy values with examples of objects evaluated in boolean context.
Python

Python Truthy and Falsy Values Explained

Learn what truthy and falsy mean in Python, see which standard values are falsy in Boolean contexts, and how to use truthiness in conditionals and custom classes.

Pythontruthyfalsyboolean context
Illustration of Python boolean values with True and False symbols and a logic gate metaphor.
Python

Python Boolean Values: Truthiness and Operators

python boolean values: Learn how Python boolean values work: True/False, truthiness rules, boolean operators, and common pitfalls in real code.

pythonbooleantruthinessoperators
Illustration of Python boolean logic with true and false symbols and conditional branching.
Python

Python Bool Usage: Truthiness and Boolean Logic

Learn how Python's bool type and truthiness rules affect conditionals, loops, and comparisons, with practical patterns for cleaner code.

PythonBooleansTruthinessConditionals
Illustration of a complex plane with Python code snippets showing arithmetic operations on complex numbers.
Python

Python Complex Number Operations: Syntax and Practical Use

Learn how to create, manipulate, and format complex numbers in Python, including arithmetic, cmath functions, comparison limits, common mistakes, and performance considerations.

complex numberscmath modulePython numeric typesarithmetic operations
A diagram showing a complex number with real and imaginary axes, highlighting the .real and .imag attributes in Python.
Python

Python Complex Numbers: Accessing Real and Imaginary Parts

Learn how to access the real and imaginary parts of Python complex numbers using .real and .imag, with practical examples and edge cases.

complex numbersPython numeric typesreal partimaginary part
Illustration of a complex plane with a point representing a complex number and its real and imaginary axes labeled.
Python

Python Complex Numbers: Syntax, Operations, and the cmath Module

python complex numbers: Learn how Python represents complex numbers, performs arithmetic, and uses the cmath module for advanced math functions with practical examples.

Pythoncomplex numberscmathnumeric computing
Illustration comparing Python's float binary representation with the decimal module's exact decimal arithmetic.
Python

Python Decimal vs Float: Choosing the Right Numeric Type

Compare Python's float and Decimal types. Learn why binary floating point shows values like 0.30000000000000004, how Decimal controls rounding, and when to choose each.

decimal modulefloating pointnumeric precisionPython types