ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
s = "Hello World"
print(s.swapcase())
print(s.title())
print("  a b  ".split())
  1. A. hELLO wORLD Hello World ['a', 'b']
  2. B. HELLO WORLD hello world ['', 'a', 'b', '']
  3. C. hELLO wORLD HELLO WORLD ['a', 'b', '']
  4. 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

Exams that ask this topic