0%

🪄 A Mirror, A Whisper

In Python, you can reverse a string with slicing: text[::-1]. The [start:stop:step] syntax lets you control how you read the string.
🔮 reversed = text[::-1]

A string is a path of characters. Normally you walk forward from the first letter to the last. But sometimes you need to walk backward. Read the end before the beginning. See the reflection. The slicing syntax with step = -1 turns your string into a mirror. The last character becomes first. The first becomes last. A perfect reverse.

🕯️ 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 step of 1 moves forward. A step of -1 moves backward. This works on any sequence, not just strings.

The syntax text[::-1] means: take the entire string (empty start and stop) and walk through it one character at a time but backward (step = -1). The result is a new string that is the exact reverse of the original. The original string remains untouched.
  • Works on any sequence: strings, lists, tuples
  • Creates a new reversed object, does not modify the original
  • Can reverse with custom start and end positions: text[4:1:-1]
  • For lists, reversed(list) returns an iterator, while list[::-1] returns a new list
💡 Use text[::-1] for simple string reversal. For large sequences where you need to iterate in reverse without creating a copy, use reversed(text) which returns an iterator. For checking palindromes, compare text == text[::-1] after normalizing case and removing spaces.
InputSlicingOutput
“Hello”“Hello”[::-1]“olleH”
“madam”“madam”[::-1]“madam”
“Python”“Python”[::-1]“nohtyP”
[1, 2, 3, 4][1, 2, 3, 4][::-1][4, 3, 2, 1]
(“a”, “b”, “c”)(“a”, “b”, “c”)[::-1](“c”, “b”, “a”)
⚠️ Slicing with [::-1] creates a complete copy of the sequence. For very large strings or lists (millions of elements), this uses significant memory. If you only need to iterate in reverse without storing the reversed version, use reversed() instead for memory efficiency.
Examples

Python

# Reversing a string

word = “whisper”

backwards = word[::-1]

print(backwards)

# Output: repsihw

Python

# Checking for palindromes

def is_palindrome(text):

cleaned = text.lower().replace(” “, “”)

return cleaned == cleaned[::-1]

print(is_palindrome(“A man a plan a canal panama”))

# Output: True

print(is_palindrome(“python”))

# Output: False

Python

# Partial reverse with custom start and stop

text = “programming”

partial = text[4:8:-1]

print(partial)

# Output: “rg”

# Walk backward from index 7 to 4 (not including 4)

Common Mistakes
  • Forgetting that [::-1] creates a new copy, thinking it reverses in place
  • Using [::-1] on integers, this only works on sequences not numbers
  • Confusing reversed() (returns iterator) with [::-1] (returns new sequence)

⚡ Whisper

The mirror does not change what it reflects. It only shows the other side. Your original string remains. The reversed version is a whisper from the end of time, reading backward to reveal what was hidden.