What is the output of the Python expression: 'UnitedArabEmirates'[6:10]?

Answer and explanation

Correct answer: D. 'Arab'

  1. Step 1: Index the zero-indexed string: U(0), n(1), i(2), t(3), e(4), d(5), A(6), r(7), a(8), b(9), E(10).
  2. Step 2: Python slicing `[start:stop]` includes the start index and excludes the stop index. Characters at indices 6, 7, 8, 9 are 'A', 'r', 'a', 'b', giving `'Arab'`.
Answer
'Arab'.
Why not the others: `'dAra'` starts at index 5; `'ArabE'` includes index 10; `'Emir'` begins at index 10.

Practise more Algorithms and Python Programming.

Free questions with an explanation for every one, and full timed EmSAT Achieve (UAE) mock tests.