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]
Answer and explanation
Concise answer
word[3:7]
Why this is correct
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.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
