Skip to the workspace
Pebellslearn by building

Python syntax & reference

Find the form you need, compare how it behaves, and open the complete explanation when you need more depth.

Python 3.10+ syntax; individual entries identify newer features. Browser exercises use the configured Python runner.

2 matching syntax entries

Lists, copying and mutation

Learn in depth →

A list is an ordered mutable collection. A shallow copy creates a new outer container.

items.append(value); items.extend(values); items.copy()

Example

a = [[1]]
b = a.copy()
b[0].append(2)
print(a, b)
print(a.append([3]))

Result

[[1, 2]] [[1, 2]]
None

Watch for: append and sort mutate in place and return None. Shallow copies still share nested objects.

Practise this topic →

Set operations

Learn in depth →

A set holds distinct hashable values and supports membership and set algebra.

a | b; a & b; a - b; a ^ b

Example

a, b = {1, 2}, {2, 3}
print(sorted(a | b), sorted(a & b), sorted(a - b))

Result

[1, 2, 3] [2] [1]

Watch for: {} is an empty dictionary; set() is an empty set. Do not rely on set iteration order.

Practise this topic →
Complete explanation index (91 lessons indexed)

Lists, Tuples & Sets

Technical sources and review date

Original Pebells examples. Reviewed 2026-10-28.

Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.