ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('a'.join('xyz'), 'xyz'.join(['a']), 'ab'.join(['', '']), ','.join(map(str, [1.0, 2])))
  1. A. xayaz a ab 1.0,2
  2. B. xyzaxyz a ab 1.0,2
  3. C. xayaz a ba 1.0,2
  4. D. xayaz a ab 1,2

Correct answer: A. xayaz a ab 1.0,2

join puts the separator between items, so 'a'.join('xyz') is xayaz. A single item has no separators, and joining two empty strings gives only the separator. str(1.0) is '1.0', not 1.

More Python Programming questions

Exams that ask this topic