Python Fundamentals / Collections
Lesson 23 of 38
Slicing
Slicing takes part of a list or string: items[start:stop]. The stop index isn't included. [::-1] reverses.
Key points
- text[0:3] gives the first 3
- text[-3:] gives the last 3
- text[::-1] reverses
word = "security"
print(word[:3]) # sec
print(word[::-1]) # ytirucesQuiz · +10 XP
What does "python"[1:4] give?
Log in to save progress and earn XP.