Back
+10 XP
Concept

Grabbing the Last Letter [-1]

Want the last character without counting the whole string? Use negative numbers:

python
code = "DRAGON"
print(code[-1])  # 'N' (the very last character!)
print(code[-2])  # 'O' (second from the back)

# 31. Grabbing the Last Letter [-1] Want the last character without counting the whole string? Use negative numbers: ```python code = "DRAGON" print(code[-1]) # 'N' (the very last character!) print(code[-2]) # 'O' (second from the back) ``` Negative numbers wrap around from right to left. `-1` is always your shortcut to the caboose.

Checkpoint

What does `"CYBER"[-1]` give you?

Practice

Create `hero = "BATMAN"` and print the very last letter using `[-1]`.

Terminal
01
Tap code blocks below to assemble
Available Blocks