🕯️ Magic Note
Multiplication works with tuples, lists, and strings. For tuples, the result is a new tuple containing the original elements repeated in order. The operation does not nest the tuple inside itself. It flattens the repetition, creating one longer sequence.
- Works with strings, tuples, and lists
- Does not modify the original sequence
- Returns a new sequence with repeated elements
- Multiplying by 1 returns a copy, by 0 returns an empty sequence
| Input | Operation | Output |
|---|---|---|
| (1,2,3) | * 2 | (1,2,3,1,2,3) |
| (“a”,”b”) | * 3 | (“a”,”b”,”a”,”b”,”a”,”b”) |
| (5,) | * 4 | (5,5,5,5) |
| (1,2) | * 1 | (1,2) |
| (1,2) | * 0 | () |
Python
# Creating repeated patterns with tuples
pattern = (0, 1)
rhythm = pattern * 4
print(rhythm)
# Output: (0, 1, 0, 1, 0, 1, 0, 1)
Python
# Setting default coordinates
default_position = (0, 0, 0)
grid = [default_position] * 5
print(grid)
# Output: [(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)]
# With tuples, each reference points to the same immutable tuple, which is safe because tuples cannot be changed
Python
# String repetition works the same way
whisper = “echo “
print(whisper * 3)
# Output: echo echo echo
- Expecting multiplication to modify the original tuple, it always returns a new tuple
- Using multiplication with lists containing mutable objects and wondering why changes affect all repetitions
- Forgetting that multiplying by zero returns an empty sequence, which may cause unexpected behavior in loops
⚡ Whisper
A single step repeated becomes a journey. A single note repeated becomes a rhythm. The tuple knows this truth. One pattern, many echoes. Persistence creates beauty, even in silence.