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 an empty set in Python showing the set() constructor and a blank container with no elements.
Python

How to Create a Python Empty Set

Learn the correct way to create a Python empty set, why {} creates an empty dictionary, and how to use empty sets effectively in real code.

pythonsetsdata structurespython syntax
Illustration of Python set initialization with a set literal and constructor
Python

Python Set Initialization: Syntax, Methods, and Pitfalls

Learn the correct ways to initialize sets in Python: literals, the set() constructor, comprehensions, empty sets, and common pitfalls to avoid.

setpythoninitializationdata structures
A set of distinct colored blocks arranged in a circle, illustrating Python's unordered unique collection type.
Python

Python Set Declaration: Syntax and Pitfalls

python set declaration: Learn how to declare sets in Python, including literals, the set() constructor, and the empty-set gotcha that confuses many developers.

Pythonsetsdata structuresPython syntax
Illustration of a Python set as a collection of unique elements with fast membership lookup, showing the hash-based structure.
Python

Python Set: Operations, Performance, and Use Cases

python set: Learn how Python sets store unique elements, perform union and intersection operations, and provide fast membership testing for practical data tasks.

set operationsdata structurespython collectionsmembership testing
Illustration of a Python function returning multiple values, shown as a tuple being unpacked into separate variables.
Python

Python Multiple Return Values: Tuples, Namedtuples, and Dataclasses

python multiple return values: Learn how to return multiple values from a Python function using tuples, namedtuples, dataclasses, and other containers, with practical...

pythontuplesunpackingnamedtuple
Python code snippet showing a function returning a tuple that is unpacked into two variables
Python

Python Tuple Return Values: Syntax and Unpacking

Learn how to return tuples from Python functions, unpack them into separate variables, and choose between tuples, named tuples, and dataclasses.

pythontuplesfunction-returnunpacking
A Python namedtuple example showing field access and structure
Python

Python namedtuple Usage: Practical Examples

python namedtuple usage: Learn how to use Python's namedtuple to create readable, lightweight data structures, including syntax, defaults, performance, and when to pre...

namedtuplePython collectionstupledataclass
Illustration of a Python namedtuple showing named fields as labeled slots in an immutable container.
Python

Python Namedtuple: Lightweight, Readable Data Containers

python namedtuple: Learn how Python's namedtuple creates lightweight immutable data containers, when to use them over dictionaries or classes, and their performance tr...

namedtuplepythondata structuresimmutability
Diagram showing a nested tuple structure with an outer tuple containing multiple inner tuples, each with distinct colored elements.
Python

Python Nested Tuples: Syntax, Access, and Use Cases

Learn how to create and access nested tuples in Python, understand their immutability, and see when nested tuples are a better choice than lists, namedtuples, or dataclasses.

nested tuplestuple unpackingimmutabilitydata structures
Diagram showing a tuple being used as a key to access a value in a Python dictionary.
Python

Python Tuple as Dictionary Key: How and Why

python tuple as dictionary key: Learn how to use Python tuples as dictionary keys, why they work, common pitfalls, and when to choose alternatives like dataclasses.

Pythontuplesdictionarieshashable