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 list with an element being appended at the end.
Python

Python list append: Usage, Behavior, and Performance

How Python's list.append() works, what it returns, its time complexity, common mistakes, and when to use extend() or list comprehensions.

Pythonlist methodsdata structuresperformance
Diagram comparing append, extend, and insert operations on a Python list, showing how each method adds elements at different positions.
Python

Adding Elements to a Python List: append, extend, insert

Learn how to add elements to a Python list with append, extend, insert, and the + operator, including runtime costs and common mistakes.

Python listslist methodsappendextend
Diagram showing a Python list with an element being replaced via index assignment.
Python

Python List Modify Element: Indexing and Iteration

python list modify element: Learn how to modify elements in a Python list using direct indexing, slice assignment, iteration with enumerate, and list comprehensions, w...

listmutationindexingiteration
Diagram showing a Python list of colored blocks being sliced in reverse direction with an arrow moving from right to left.
Python

Python List Reverse Slicing Explained

Learn how to reverse and slice Python lists using negative step values, including full reversal, subset extraction, and skipping elements.

python-slicingpython-listsreverse-slicingpython-syntax
Illustration of Python list slicing showing a list with a highlighted slice segment
Python

Python List Slicing: Syntax, Patterns, and Pitfalls

Learn how to use Python list slicing to extract subsequences, modify lists, and handle edge cases with clear examples and performance notes.

list slicingPython listssequence operationsPython syntax
Illustration of Python negative list indexing showing a list with indices -1, -2, -3 from the end and a pointer to the last element.
Python

Python Negative List Indexing: Syntax and Pitfalls

Learn how Python negative list indexing works, including index mapping, slicing behavior, and common edge cases to avoid off-by-one errors and IndexError exceptions.

Python listsnegative indexinglist slicingPython syntax
Illustration of Python list indexing showing a list with highlighted element at position 2 and negative index -1 pointing to the last element.
Python

Python List Indexing: Syntax, Slicing, and Edge Cases

python list indexing: Understand Python list indexing rules, negative indices, slicing with step, error handling, and performance characteristics for reliable code.

list indexingPython listsslicingIndexError
Visual representation of Python list constructor converting an iterable into a list
Python

Python List Constructor: How list() Works and When to Use It

Understand the Python list() constructor, its behavior with iterables, how it differs from list comprehensions, and the performance tradeoffs to consider.

pythonlistiterablelist-comprehension
Illustration of Python list literal syntax showing square brackets containing ordered comma-separated elements
Python

Python List Literals: Syntax and Behavior

python list literal: Learn how Python list literals work — from basic syntax and nested lists to mutability, edge cases, and when to prefer literals over list().

pythonlistsyntaxdata-structures
A clean illustration showing an empty Python list as an open container with zero items, representing the concept of an empty list in Python code.
Python

Python Empty List: Creation, Checks, and Common Pitfalls

python empty list: Learn how to create empty lists in Python, check emptiness with truthiness, and avoid pitfalls like mutable default arguments and None confusion.

pythonliststruthinessdefault-arguments