ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print("a" "b" * 2, ("a" + "b") * 2, "-".join(["a", "b"]) * 2, "x".join("123"))
  1. A. abb abab a-ba-b 1x2x3
  2. B. abab abab a-ba-b 1x2x3
  3. C. abab abab a-b-a-b 1x2x3
  4. D. abab abab a-ba-b x1x2x3x

Correct answer: B. abab abab a-ba-b 1x2x3

Adjacent string literals are concatenated at compile time before * is applied, so 'a' 'b' * 2 is 'ab' * 2. join puts the separator only between items, and a string is an iterable of characters.

More Python Programming questions

Exams that ask this topic