ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
s = "placement"
print(s[-100:5])
  1. A. IndexError
  2. B. place
  3. C. ''
  4. D. lacem

Correct answer: B. place

Slice bounds are clamped, never raising IndexError: -100 clamps to 0, and the slice becomes s[0:5], which is 'place'.

More Python Programming questions

Exams that ask this topic