ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('abcdef'[4:1:-2], 'abc'[::-2], 'abc'[-5:], 'abc'[5:] == '')
  1. A. ec ca abc False
  2. B. ce ca abc True
  3. C. ec ac abc True
  4. D. ec ca abc True

Correct answer: D. ec ca abc True

A negative step walks backward from index 4, taking indices 4 and 2 to give 'ec'. 'abc'[::-2] takes indices 2 and 0 to give 'ca', and a start index past the end gives an empty slice.

More Python Programming questions

Exams that ask this topic