ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('abc'[1:][::-1], 'abc'[::-1][1:], 'abcdef'[::-2][:2])
  1. A. bc cb fd
  2. B. cb ba fe
  3. C. cb ba fdb
  4. D. cb ba fd

Correct answer: D. cb ba fd

Slices apply left to right: 'bc' reversed is 'cb', and 'cba' from index 1 is 'ba'. [::-2] of 'abcdef' takes f, d, b, and the first two of those are fd.

More Python Programming questions

Exams that ask this topic