logo

AQA A-Level Computer Science practice

In Python 3, which expression extracts the substring "gram" from the string variable word containing "program"?

Try the question first, then check the answer and practise the same topic again.

At a glance

MCQ

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

In Python 3, which expression extracts the substring "gram" from the string variable word containing "program"?.

  1. A.word[3:7]
  2. B.word[2:6]
  3. C.word[4:8]
  4. 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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions