ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
s = "Hello World"
print(s.swapcase())
print(s.title())
print(" a b ".split())- A. hELLO wORLD Hello World ['a', 'b']
- B. HELLO WORLD hello world ['', 'a', 'b', '']
- C. hELLO wORLD HELLO WORLD ['a', 'b', '']
- D. hello world Hello World [' ', 'a', 'b', ' ']
Correct answer: A. hELLO wORLD Hello World ['a', 'b']
swapcase() flips the case of every letter. title() capitalizes the first letter of each word (already true here). split() with no argument splits on any whitespace AND discards leading/trailing empty strings, giving just ['a', 'b'].
More Python Programming questions
- What is printed? python print("a-b--c".split("-")) print("a-b--c".split("-", 1))
- What is printed? python d = {"b": 2, "a": 1, "c": 3} print(sorted(d.items())) print(dict(sorted(d.items())))
- What is printed? python from functools import lrucache calls = [] @lrucache(maxsize=None) def f(n): calls.append(n) return n n f(2); f(3)…
- What is printed? python def deco(f): def wrapper(a, k): wrapper.calls += 1 return f(a, k) wrapper.calls = 0 return wrapper @deco def h()…
- What is printed? python def decoratorwithargs(prefix): def actual(f): def wrapper(a, k): return prefix + str(f(a, k)) return wrapper…
- What is printed? python class A: def init(self): self.x = 1 def enter(self): return self def exit(self, a): self.x = 0 return False with…