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 tuple being repeated with the asterisk operator to create a longer tuple.
Python

Python Tuple Repetition with the * Operator

Learn how Python tuple repetition works with the * operator, including syntax, mutable element pitfalls, performance tradeoffs, and alternatives.

pythontuplesequence-operatorsimmutability
Illustration of two tuple blocks merging into one combined tuple using a plus sign, representing Python tuple concatenation.
Python

Python Tuple Concatenation: Combining Tuples with + and *

Learn how to concatenate tuples in Python using + and *, understand immutability, and avoid common performance pitfalls.

pythontuplesconcatenationimmutability
Illustration comparing Python tuple and list, highlighting immutability and dynamic resizing.
Python

Python Tuple vs List: Key Differences

python tuple vs list: Understand the practical differences between Python tuples and lists, including mutability, memory usage, and when each is the right choice.

Pythontupleslistsimmutability
Illustration of an immutable Python tuple shown as a fixed sealed container holding references to separate mutable and immutable objects.
Python

Python Tuple Immutability: What It Means in Practice

Understand Python tuple immutability in practice: what operations fail, why immutability is shallow, how hashability works, memory tradeoffs, and when tuples are the better choice.

tuplesimmutabilitypython-data-structureshashability
Illustration of a Python tuple as a row of indexed boxes with one element highlighted by a pointer.
Python

Python Tuple Index: Access Elements by Position

Learn how to access tuple elements by position, use the index() method, slice tuples, and avoid common indexing errors in Python.

pythontuplesindexingdata-structures
Illustration of counting elements in a Python tuple using count() and len() methods.
Python

Python Tuple Count: Using count() and len()

Learn how to count elements in Python tuples: use count() for occurrences of a value and len() for total items, with examples and edge cases.

tuplescount()len()sequence methods
Diagram showing a tuple slice with start, stop, and step parameters producing a new tuple
Python

Python Tuple Slicing: Syntax, Steps, and Pitfalls

Learn how to slice tuples in Python, including start, stop, and step behavior, negative indexes, and common edge cases.

tuple slicingpython sequencesimmutabilitystep parameter
Diagram showing a tuple with elements and an index arrow pointing to the third element, illustrating Python tuple indexing.
Python

Python Tuple Indexing: Syntax, Errors, and Practical Use

python tuple indexing: Understand how Python tuple indexing works: positive and negative indices, slicing, nested tuples, common errors, and when tuples outperform lists.

Pythontupleindexingsequence
Illustration showing a tuple being split into fixed first and last elements with a starred middle section in Python
Python

Python Starred Tuple Unpacking: Syntax and Use Cases

Learn how Python's starred tuple unpacking uses the * operator to assign values, handle variable-length sequences, and avoid common errors.

Pythontuple unpackingstarred expressionsiterable unpacking
Illustration of Python iterable unpacking with a star expression splitting a list into separate parts.
Python

Python Extended Iterable Unpacking in Practice

python extended iterable unpacking: Learn how Python's extended iterable unpacking works, including star expressions, nested unpacking, and common pitfalls.

pythoniterable unpackingstar expressionstuple unpacking