Python Comparisons
The pairs of things Python beginners mix up, compared side by side. Each page gives a quick answer, a comparison table, runnable code that proves the difference, and a rule of thumb for choosing.
Data types and structures
Python List vs Tuple: Differences and When to Use Each
A **list** is a changeable (mutable) sequence written with `[]`, while a **tuple** is a fixed (immutable) sequence written with `…
Python List vs Set: Differences and When to Use EachA **list** keeps items in order and allows duplicates, while a **set** stores only unique items with no index and checks membersh…
Python List vs Dictionary: Differences and When to Use EachA **list** stores values by position (`items[0]`), while a **dictionary** stores values by a meaningful key (`prices["pen"]`); us…
Python Mutable vs Immutable Objects Explained**Mutable** objects (list, dict, set) can be changed in place after creation, while **immutable** objects (int, float, str, tuple…
Operators and syntax
Python is vs == Operator: What Is the Difference?
`==` checks whether two objects have **equal values**, while `is` checks whether they are the **exact same object** in memory; us…
Python Division (/) vs Floor Division (//)`/` is **true division** and always returns a float (`7 / 2` is `3.5`), while `//` is **floor division** and rounds the result do…
Python break vs continue vs pass: Differences`break` stops the whole loop, `continue` skips the rest of the current iteration and moves to the next one, and `pass` does nothi…
Functions and methods
Python append() vs extend(): What Is the Difference?
`append(x)` adds **one** item to the end of a list (even if it is a list), while `extend(iterable)` adds **each element** of an i…
Python sort() vs sorted(): What Is the Difference?`list.sort()` sorts a list **in place** and returns `None`, while `sorted(iterable)` leaves the original untouched and **returns …
Python remove() vs pop() vs del: What Is the Difference?`remove(x)` deletes the first item **equal to a value**, `pop(i)` deletes the item at an **index and hands it back**, and `del` i…
Python print() vs return: What Is the Difference?`print()` **displays** a value on the screen and gives you nothing to work with, while `return` **sends a value back** to the cod…
Python str() vs repr(): What Is the Difference?`str()` returns a **readable** version of an object meant for users, while `repr()` returns an **unambiguous** version meant for …
Python Deep Copy vs Shallow Copy: What Is the Difference?A **shallow copy** makes a new outer container but still shares the inner objects with the original, while a **deep copy** recurs…
Concepts
Python Function vs Method: What Is the Difference?
A **function** is a standalone block of code you call by name, like `len(items)`, while a **method** is a function that belongs t…
Python Module vs Package: What Is the Difference?A **module** is a single Python file (such as `utils.py`) that you can import, while a **package** is a directory that groups sev…
Python Iterator vs Generator: What Is the Difference?An **iterator** is any object that returns one item at a time through `__next__()`, and a **generator** is a simpler way to creat…
Python @staticmethod vs @classmethod: What Is the Difference?A `@classmethod` receives the **class itself** as its first argument (`cls`) and can create or configure instances, while a `@sta…
Explore more
Python ReferencePython ProgramsPython How-To GuidesPython Cheat SheetsPython glossaryPython tutorial