Predict the Slice Output
Beginner · Predict the output · from Python Strings: Create, Access, Slice, and Manipulate Text
From the lesson: Python Strings: Create, Access, Slice, and Manipulate Text
Think about your phone. Almost everything you see on the screen is text: names in your contacts, messages from friends, search results, notifications. Behind the scenes, all of that text is handled by strings.
Read the lessonWithout running the code, predict what each line will print. Remember: slicing uses [start:stop] where stop is excluded.
Write your predictions as comments, then run the code to check.
word = "Hello"
print(word[1:4]) # Your prediction:
print(word[:3]) # Your prediction:
print(word[2:]) # Your prediction:
More Strings exercises
- Build a Greeting with ConcatenationBeginner
- Get the First and Last CharacterBeginner
- Reverse a StringBeginner
- Fix the Bug: Mutating a StringBeginner
- Check If a Word Is in a SentenceBeginner
- Extract a Domain from an Email AddressBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz