ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
s = "abcbaXabcba"
print(s.strip("ab"), s.removeprefix("ab"), s.lstrip("cba"))
  1. A. cbaXabc cbaXabcba Xabcba
  2. B. cbaXabcba cbaXabcba Xabcba
  3. C. cbaXabc cbaXabcba cbaXabcba
  4. D. cbaXc cbaXabcba Xabcba

Correct answer: A. cbaXabc cbaXabcba Xabcba

strip(chars) treats its argument as a SET of characters and removes them from both ends until a character outside the set appears: from the left a, b go and c stops it; from the right a, b go and c stops it, leaving cbaXabc. removeprefix removes the exact string "ab" once. lstrip("cba") removes any of a, b, c from the left up to X: Xabcba.

More Python Programming questions

Exams that ask this topic