Recall & Review
beginner
What is string indexing in Python?
String indexing means accessing individual characters in a string using their position number, starting from 0 for the first character.
Click to reveal answer
beginner
How does positive indexing work in Python strings?
Positive indexing starts at 0 for the first character and increases by 1 for each next character to the right.
Click to reveal answer
beginner
What is negative indexing in Python strings?
Negative indexing starts at -1 for the last character and decreases by 1 moving left, allowing easy access from the end.
Click to reveal answer
beginner
Example: What character does 'hello'[-2] return?
It returns 'l' because -1 is 'o', so -2 is the second last character 'l'.
Click to reveal answer
intermediate
What happens if you use an index out of range in string indexing?
Python raises an IndexError because the position does not exist in the string.
Click to reveal answer
What is the index of the first character in a Python string?
✗ Incorrect
Python strings start indexing at 0 for the first character.
What does the index -1 represent in a Python string?
✗ Incorrect
Negative index -1 points to the last character in the string.
If s = 'Python', what is s[3]?
✗ Incorrect
Index 3 is the fourth character, which is 'h' in 'Python'.
If s = 'Python', what is s[-4]?
✗ Incorrect
Negative index -4 points to the third character from the start, which is 't'.
What error occurs if you try to access s[10] when s = 'Python'?
✗ Incorrect
IndexError occurs because index 10 is outside the string length.
Explain how positive and negative indexing work in Python strings.
Think about counting characters from left and right.
You got /3 concepts.
What happens if you try to access a string character using an index that is too large or too small?
Consider what Python does when you ask for something that does not exist.
You got /3 concepts.