🕯️ Magic Note
The + operator is overloaded in Python. For numbers it adds. For strings it concatenates. For lists it merges. Behind the scene, Python allocates new memory and copies elements from both lists into a fresh container.
- Works with empty lists: [] + [1, 2] returns [1, 2]
- Can chain multiple lists: a + b + c + d
- Originals remain unchanged, perfect for immutable workflows
- Preserves the order of elements from both lists
| list1 | list2 | Result |
|---|---|---|
| [1, 2] | [3, 4] | [1, 2, 3, 4] |
| [“a”, “b”] | [“c”] | [“a”, “b”, “c”] |
| [] | [5, 6, 7] | [5, 6, 7] |
| [True, False] | [True] | [True, False, True] |
Python
# Merge two lists of tasks
morning_tasks = [“write code”, “drink coffee”]
evening_tasks = [“review code”, “conjure ideas”]
all_tasks = morning_tasks + evening_tasks
print(all_tasks)
# Output: [“write code”, “drink coffee”, “review code”, “conjure ideas”]
# morning_tasks and evening_tasks are unchanged
Python
# Chaining three lists together
first = [1, 2]
second = [3, 4]
third = [5, 6]
combined = first + second + third
print(combined)
# Output: [1, 2, 3, 4, 5, 6]
Python
# Mixing different data types
numbers = [10, 20, 30]
words = [“python”, “magic”]
mixed = numbers + words
print(mixed)
# Output: [10, 20, 30, “python”, “magic”]
- Using + between a list and a non list, TypeError: can only concatenate list (not “int”) to list
- Forgetting that + creates a new list, not modifying the original
- Confusing + with append() which adds a single element as a nested item
⚡ Whisper
Two streams become one river. No resistance. No loss. Each drop keeps its place. The merge is silent, the originals remain sacred.