Concept
Reversing Strings (::-1)
Add a third number `[start:stop:step]` to jump characters:
python
digits = "0123456789"
print(digits[::2]) # "02468" (skips by 2)
print(digits[::-1]) # "9876543210" (flips backwards!)
# 33. Reversing Strings (::-1) Add a third number `[start:stop:step]` to jump characters: ```python digits = "0123456789" print(digits[::2]) # "02468" (skips by 2) print(digits[::-1]) # "9876543210" (flips backwards!) ``` `[::-1]` is the famous Python trick to reverse any string backwards in one shot without loops.
Checkpoint
What does `"TACO"[::-1]` output?
Practice
Flip the secret code `message = "edoc_terces"` backwards using `[::-1]` and print the revealed text.
01
Tap code blocks below to assemble
Available Blocks