ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
s = " Py Thon "
print(s.strip().lower().replace(" ", "").count("o"), s.split(" ").count(""))- A. 1 0
- B. 1 4
- C. 2 4
- D. 1 2
Correct answer: B. 1 4
strip, lower and replace give "python", which has one 'o'. split(" ") with an explicit separator does NOT merge spaces: " Py Thon " becomes ['', '', 'Py', 'Thon', '', ''], which has 4 empty strings.
More Python Programming questions
- What is printed? python def f(x): try: r = 10 // x except ZeroDivisionError: return "Z" else: return r finally: print("F", end=" ")…
- What is printed? python class P: def repr(self): return "R" def str(self): return "S" print(P(), [P()], f"{P()!r}")
- What is printed? python class K: def eq(self, other): return True try: print({K(): 1}) except TypeError: print("TypeError")
- What is printed? python it = iter([1, 2, 3, 4, 5]) print(list(zip(it, it)))
- What is printed? python x = 1 x, y = x + 1, x 10 print(x, y)
- What is printed? python print(any([]), all([]), all([[]]))