ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'xxxy'
print(s.rstrip('y'), s.strip('x'), repr(s.lstrip('xy')))- A. xxx y 'y'
- B. xxx y ''
- C. xxx xy ''
- 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
- What is printed? python print('abc' < 'abcd', 'Z' < 'a', '10' < '9')
- What is printed? python i = 0 while (i := i + 1) < 4: pass print(i)
- What is printed? python print(float('nan') < 0, float('inf') > 10 300, -float('inf') < -10 300)
- What is printed? python print(10 309 > float('inf'), end=' ') try: float(10 309) except OverflowError as e: print(e)
- What is printed? python from collections import Counter d = {'a': 1, 'b': 2} v = d.values() d['c'] = 3 print(len(v), list(v))
- What is printed? python print(frozenset([1, 2]) == {1, 2}, {frozenset([1]): 'x'}[frozenset([1])])