0%

🪄 The Mirror Doesn’t Show It All

Step slicing means [start:stop:step]. Here, [::-2] walks backward, skipping one each time. A perfect glimpse into Python’s slice logic.
🔮 reflection = “mirror”[::-2]

A mirror shows everything in reverse. But some mirrors are selective. They skip what they do not want to reflect. They reveal only fragments. The truth is there, but not the whole truth. The [::-2] slice is that selective mirror. It walks backward through the string from end to start, but it only shows every second character. The rest remain hidden.

🕯️ Magic Note

Slicing follows the pattern [start:stop:step]. When start and stop are omitted, Python uses the beginning and end of the sequence. A positive step moves forward from left to right. A negative step moves backward from right to left. The number determines how many characters to skip each time.

The syntax “mirror”[::-2] tells Python to start at the end of the string, move backward, and take every second character. Starting from r (index 5, the last character), then skip one to reach o (index 3), then skip one to reach r (index 1), then skip one to reach i (index -1? no, the slice stops when reaching the beginning). The result is “ror”.
  • Negative step means traverse from right to left
  • The step value determines how many indices to move each time
  • Step of 2 means take one, skip one, take one, skip one
  • Works on strings, lists, and tuples
💡 Use negative step slicing for reverse operations like [::-1] for full reverse. Use [::-2] for every other character from the end. For forward step slicing, use [::2] to take every second character from the beginning. Step slicing is memory efficient because it creates new sequences without loops.
Input StringSliceResult
“mirror”[::-1]“rorrim”
“mirror”[::-2]“ror”
“mirror”[::2]“mio”
“mirror”[1::2]“irr”
“python”[::-2]“nhy”
⚠️ When using negative step slicing, remember that the start and stop parameters also follow the direction of the step. For [::-2] with empty start and stop, Python automatically uses the appropriate ends of the sequence. If you specify custom start and stop with a negative step, the start must be greater than the stop because you are moving backward.
Examples

Python

# Every second character from the end

word = “mirror”

reflection = word[::-2]

print(reflection)

# Output: ror

Python

# Comparing forward and backward step slicing

text = “abcdefgh”

forward = text[::2]

backward = text[::-2]

print(f”Forward: {forward}”)

print(f”Backward: {backward}”)

# Output: Forward: aceg

# Output: Backward: hfdb

Python

# Custom start position with negative step

word = “magical”

result = word[5::-2]

print(result)

# Output: agm

Common Mistakes
  • Confusing the direction when mixing positive and negative start values with negative steps
  • Forgetting that step slicing creates a new sequence, not a view of the original
  • Assuming a step of 0 works, Python raises a ValueError because step cannot be zero

⚡ Whisper

The mirror shows fragments. Not the whole face, but enough to recognize. Every second step reveals a new truth while shadows hide the rest. The reflection is honest but incomplete. That is the magic of the step slice.