ProgrammingModerateTCS NQT · Infosys

What does ','.join([1, 2]) do in Python 3?

  1. A. Returns '1,2'
  2. B. Raises TypeError because join needs str items
  3. C. Returns '[1, 3]'
  4. D. Returns '12'

Correct answer: B. Raises TypeError because join needs str items

str.join accepts only strings, so an int item raises a TypeError. Convert items with str() or map(str, ...) first.

More Python Programming questions

Exams that ask this topic