ProgrammingModerateInfosys · Accenture · Capgemini pattern

What is printed?

What is printed?
s = "hello"
print(s[::-2])
  1. A. oll
  2. B. hlo
  3. C. olh
  4. D. ol

Correct answer: C. olh

With step -2 the slice starts at the last index (4, 'o') and moves back two at a time: index 4 'o', index 2 'l', index 0 'h'.

More Python Programming questions

Exams that ask this topic