Editor

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 lesson

Without 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

All Python exercises · 50 practice problems · Python Fundamentals quiz