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 negative modulo showing a number line with floor division and remainder sign.
Python

Python Negative Modulo: Sign and Behavior Explained

Understand Python's negative modulo behavior: why the result takes the divisor's sign, how floor division and divmod relate, and where Python differs from C-like languages.

modulo operatorfloor divisionnegative numbersdivmod
Illustration of Python divmod function returning a tuple of quotient and remainder from division.
Python

Python divmod: Getting Quotient and Remainder in One Call

python divmod: Learn how Python's divmod returns quotient and remainder together, its behavior with integers and floats, and practical use cases.

Pythonbuilt-in functionsinteger arithmeticdivision
Illustration of the Python modulo operator showing remainder calculation with positive and negative operands.
Python

Python Modulo Operator: Behavior and Practical Use

Learn how Python's modulo operator returns remainders, why negative operands can be surprising, and how it works with floor division. Includes practical examples and edge cases such as division by zero and floating-point precision.

modulo operatorfloor divisionnegative numbersremainder
Diagram contrasting Python true division and floor division results for positive and negative numbers
Python

Python Division vs Floor Division: Key Differences

Learn the difference between Python's / and // operators, including behavior with negative numbers, floats, and practical use cases.

Pythondivision operatorsfloor divisioninteger arithmetic
Illustration of Python floor division showing a number line where -4.5 rounds down to -5, contrasting with truncation to -4.
Python

Python Floor Division: Behavior and Edge Cases

Understand how Python's // operator rounds toward negative infinity, how it relates to modulo, and when to prefer it over true division.

floor divisioninteger divisionmodulonegative numbers
Illustration of Python integer division showing floor division on a number line.
Python

Python Integer Division: How // Works and When to Use It

Understand Python's floor division with //, including negative operands, floats, and when to use divmod() for quotient and remainder.

integer divisionfloor divisionpython operatorsdivmod
Illustration of Python integer operations showing division, bitwise shifts, and large number representation
Python

Python Integer Operations: Key Behaviors and Pitfalls

python integer operations: Understand Python integer operations: division, modulo, bitwise, arbitrary precision, and performance tradeoffs for large numbers.

PythonInteger ArithmeticBitwise OperatorsArbitrary Precision
Illustration of Python integer conversion showing a string being parsed into a numeric integer object with a gear icon representing arithmetic operations.
Python

Python int Usage: Conversion, Arithmetic, and Pitfalls

Understand the int() constructor, base conversion, arithmetic behavior, large integers, and common pitfalls for reliable Python code.

int() constructortype conversioninteger arithmeticfloor division
Illustration of a mutable list and an immutable tuple, with a lock symbol on the tuple indicating hashability.
Python

Python Mutable vs Hashable: What Every Developer Should Know

Understand why mutable built-in types are not hashable in Python, how hashability affects dict keys and set membership, and when to override __hash__ and __eq__ in custom classes.

PythonHashableMutableDictionary
Illustration of Python hashable types showing a dictionary and set with a hash function symbol
Python

Python Hashable Types: Dict Keys and Set Members

Learn what makes a Python type hashable, why dictionary keys and set members require it, and how to implement __hash__ and __eq__ correctly.

hashabledict keysset membership__hash__