ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'xxxy'
print(s.rstrip('y'), s.strip('x'), repr(s.lstrip('xy')))
  1. A. xxx y 'y'
  2. B. xxx y ''
  3. C. xxx xy ''
  4. D. xxx y 'xxxy'

Correct answer: B. xxx y ''

rstrip('y') removes the trailing y, leaving 'xxx'. strip('x') removes x from both ends, leaving 'y'. lstrip('xy') removes every leading character that is x or y, which is the whole string, so the result is empty.

More Python Programming questions

Exams that ask this topic