ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'hello'
print(s[1:-1][::-1], s[-1:0:-2])
  1. A. lle lo
  2. B. ell ol
  3. C. lle oh
  4. D. lle ol

Correct answer: D. lle ol

s[1:-1] is 'ell', and reversing it gives 'lle'. s[-1:0:-2] takes index 4 and then index 2, which are o and l.

More Python Programming questions

Exams that ask this topic