Indexing text
Python · Unit 6: Strings
- Full plan
- Python
- 10 exercises
A string is a row of characters, like a list of letters.
Each character has its index starting at 0, and from the end you count -1, -2…
name = "Jordan"
print(name[0])
print(name[1])
print(name[-1])Prints
J o n
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Predict the output
Spaces are characters too. What does it print?
3. Complete the code
Complete it to print the last letter of "Emily".
4. Predict the output
What does this code print?
5. Multiple choice
What does this code do?
6. Complete the code
Complete it so it prints only "Maya".
7. Find the bug
This program should print "Jason" with a capital J. Which line has the error?
8. Predict the output
What does this code print?
9. Put the lines in order
Order the function that hides a phone with
*and shows only the last 4 digits.10. Find the case that fails
initial(name)should return the first letter of the name, or an empty string""if the name is empty. Which call breaks it?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.