Concept
Chopping Strings: Slicing [start:stop]
Cut out a chunk of text using `[start:stop]`. Golden rule: `start` is included; `stop` is **strictly excluded**:
python
game = "CYBERPUNK"
print(game[0:5]) # "CYBER" (indices 0, 1, 2, 3, 4)
print(game[:5]) # "CYBER" (start defaults to 0)
print(game[5:]) # "PUNK" (stop runs to the end)
# 32. Chopping Strings: Slicing [start:stop] Cut out a chunk of text using `[start:stop]`. Golden rule: `start` is included; `stop` is **strictly excluded**: ```python game = "CYBERPUNK" print(game[0:5]) # "CYBER" (indices 0, 1, 2, 3, 4) print(game[:5]) # "CYBER" (start defaults to 0) print(game[5:]) # "PUNK" (stop runs to the end) ```
Checkpoint
What does `"PYTHON"[0:2]` give you?
Practice
Given `word = "PANCAKE"`, slice out the first 3 letters (`"PAN"`) and print it.
01
Tap code blocks below to assemble
Available Blocks