ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print('Hello'[1:3] + 'Hello'[-1], len('Hello'[10:]), 'Hello'[::2])
  1. A. elo 0 Hel
  2. B. elo 1 Hlo
  3. C. el o 0 Hlo
  4. D. elo 0 Hlo

Correct answer: D. elo 0 Hlo

'Hello'[1:3] is 'el' and [-1] is 'o'. A slice starting past the end is empty, so its length is 0, and [::2] takes every second character.

More Python Programming questions

Exams that ask this topic