ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print('abc'[-1:-4:-1], 'abc'[5:], 'abc'[-10:2])
  1. A. cbaab
  2. B. cba a
  3. C. cba ab
  4. D. cba ba

Correct answer: C. cba ab

The reversed slice gives cba, the slice past the end gives an empty string, and the slice from a very negative start gives ab. print puts a space before each empty string, leaving two spaces.

More Python Programming questions

Exams that ask this topic