ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print('x'.removeprefix('xx'), 'hello'.removesuffix('llo'), 'abc'.removeprefix(''))- A. x hello abc
- B. x hel abc
- C. x he ab
- D. x he abc
Correct answer: D. x he abc
removeprefix and removesuffix remove the text only when it matches exactly at that end, so 'x' does not start with 'xx' and stays x. 'hello' loses its trailing 'llo', leaving 'he'. This differs from strip(), which removes any characters from a set.
More Python Programming questions
- What is printed? python print(str.maketrans('ab', 'xy', 'c'), 'abcabc'.translate(str.maketrans('ab', 'xy', 'c')))
- What is printed? python print(sorted(['10', '9', '100', '2']), sorted(map(int, ['10', '9', '100', '2'])))
- What is printed? python print(-7 // -2, 7 // -2 -2 + 7 % -2)
- What is printed? python print(round(-2.5), round(-3.5), round(7, -1), round(15, -1), round(25, -1))
- What is printed? python print(int('12abc', 36), int('zz', 36), int('-z', 36))
- What is printed? python print(hash(-1) == hash(-2), hash(-1), hash(261 - 1))