In Python, what is the output of the string slicing expression `'GetMyMockTest'[3:7]`?

Answer and explanation

Correct answer: C. `'MyMo'`

  1. Step 1: In Python string slicing `s[start:stop]`, the element at index `stop` is excluded.
  2. Step 2: String: G(0), e(1), t(2), M(3), y(4), M(5), o(6), c(7). Slicing `[3:7]` extracts characters at indices 3, 4, 5, 6, which forms `'MyMo'`.
Answer
`'MyMo'`.
Why not the others: '`tMyM'`' begins at index 2; '`MyMock'`' includes indices 7 and 8; '`GetM'`' slices from index 0 to 4.

Practise more Python Programming, Data Structures, Algorithms, Networks and Cybersecurity.

Free questions with an explanation for every one, and full timed Saudi Secondary School Certificate mock tests.