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 two Python lists where one is an independent copy and the other shares nested elements, showing shallow versus deep copy behavior.
Python

Python List Copy: Shallow vs Deep Copy Explained

Learn how to copy lists in Python correctly: assignment vs shallow copy vs deep copy, how nested lists behave, and when to use each.

python listsshallow copydeep copycopy module
Diagram contrasting Python's in-place list.reverse() with the reversed() iterator function.
Python

Python reverse() vs reversed(): Key Differences

Python reverse vs reversed: Understand the difference between Python's list.reverse() method and the reversed() function, including memory behavior, use cases, and code examples.

Pythonlistreverseiterator
A technical illustration showing a Python sequence being traversed in reverse by the reversed() function, with a lazy iterator concept.
Python

Python reversed() Function: Syntax and Behavior

python reversed function: Learn how Python's reversed() function returns a lazy iterator, works with lists, strings, and ranges, and differs from reverse() and slicing.

reversed()built-in functionsiteratorssequence reversal
Illustration showing a Python list being reversed, with the original ascending order on the left and the reversed descending order on the right, highlighting the in-place versus copy distinction.
Python

Reverse a Python List: In-Place, Iterator, or Slicing

Learn the three ways to reverse a Python list—in-place mutation, reversed() iterators, and slicing—and when each approach fits your code.

list.reverse()reversed()Python slicingin-place mutation
Diagram showing a Python list being reversed with three different approaches: in-place reversal, iterator, and slicing.
Python

Python Reverse List: Three Ways to Reverse a List

python reverse list: Learn the three main ways to reverse a list in Python: reverse(), reversed(), and slicing with [::-1], including memory and performance tradeoffs.

pythonlist-reversalslicingreversed-function
Comparison of Python list.sort() and sorted() showing in-place modification versus new list creation.
Python

Python List Sort vs Sorted: In-Place vs New List

Learn how Python's list.sort() and sorted() differ: in-place mutation vs a new sorted list, performance, stability, and which to use.

pythonsortinglistsorted
Python sorted() function transforming an unordered list of colored blocks into an ascending ordered sequence
Python

Python sorted() Function: Syntax, Key, and Behavior

Learn how Python's sorted() function works: its syntax, key and reverse parameters, stability guarantees, and when to use it instead of list.sort().

PythonSortingData StructuresAlgorithms
Illustration of a Python list being sorted into ascending order with a downward arrow indicating the sort operation.
Python

How to Sort Python Lists with sort() and sorted()

Learn how to sort Python lists using sort() and sorted(). This guide covers key functions, reverse order, sort stability, and memory tradeoffs.

pythonlist sortingsorted()sort()
Illustration of counting occurrences of a number in a Python list using the count method
Python

Counting Occurrences in a Python List with list.count()

Learn how Python's list.count() counts exact matches, see where equality can surprise you, and find out when collections.Counter or a generator with sum() is a better choice.

list.countPython listscounting elementscollections.Counter
Illustration of a Python list with an index pointer highlighting an element position.
Python

Python List index: Finding Element Positions

python list index: Learn how to use Python's list.index() to locate elements, handle missing values, and understand its performance tradeoffs.

Pythonlist methodsindexingerror handling