Strings · Lesson 6 of 25
String indexing and slicing
Select characters and slices, including their boundaries.
8 minutes3 games
Indexing starts at zero; negative indices count from the end. A slice text[start:stop:step] includes start and stops before stop. Omit a boundary to extend to that end of the string.
word = "Python" =
P[0]
y[1]
t[2]
h[3]
o[4]
n[5]
Python
word = "Python" print(word[0], word[-1]) print(word[1:4]) print(word[:2], word[2:]) print(word[::2]) print(word[::-1])
What's the output?
word = "Python" print(word[1:4])
What will this code print?
Complete the code
Complete the reversed string.
print("code"[::])
Exercise
Extract and print 2026 from the date.
Expected output: 2026
Python
date = "2026-10-25"
Learn more from
Played 0 of 3 games
Sign in to save your progress and earn XP.