ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print('a' 'b' * 2, ('a' 'b') * 2, 'ab' * 0 == '', 'x' * 3 + 'y' * 2)
  1. A. abb abab True xxxyy
  2. B. abab abab False xxxyy
  3. C. abab abab True xxxyy
  4. D. abab abb True xxxyy

Correct answer: C. abab abab True xxxyy

Adjacent string literals are joined at compile time before the * operator applies, so 'a' 'b' * 2 is 'abab'. Multiplying by zero gives an empty string.

More Python Programming questions

Exams that ask this topic