logo

Question detail

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

Try the question, check the answer, then read the explanation to understand the curriculum point.

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]

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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.