Exam-style question
Try this first
In Python 3, which expression extracts the substring "gram" from the string variable word containing "program"?.
- A.word[3:7]
- B.word[2:6]
- C.word[4:8]
- D.word[1:4]
Model answer
What a good answer should say
- word[3:7]
Explanation
Why this works
Python uses zero-based positions. In "program", the characters at positions 3, 4, 5 and 6 are "gram".
The ending index 7 is not included.
Common mistake
No common mistake is linked to this question yet.
