ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
s = "abcbaXabcba"
print(s.strip("ab"), s.removeprefix("ab"), s.lstrip("cba"))- A. cbaXabc cbaXabcba Xabcba
- B. cbaXabcba cbaXabcba Xabcba
- C. cbaXabc cbaXabcba cbaXabcba
- 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
- What is printed? python print(-7.5 // 2, -7.5 % 2, 7 // -2.0, 7 % -2.0)
- What is printed? python n = [1] print(1 in n == True, (1 in n) == True, 0 < 1 in n)
- What is printed? python class P: slots = ("x",) def init(self): self.x = 1 p = P() try: p.y = 2 except AttributeError: print("AE", end="…
- What is printed? python class T: def init(self): self.c = 0 @property def c(self): return self.c @c.setter def c(self, v): self.c = max(0…
- What is printed? python def acc(): total = 0 while True: try: x = yield total except ValueError: total = 0 continue if x is None: break…
- What is printed? python class Base: def init(self): self.log = ["Base"] class L(Base): def init(self): super().init() self.log.append("L")…