ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(','.join(['a', 'b']), ','.join('ab'), '%s' % ['a', 'b'], str(('a',)))
  1. A. a,b a,b a,b ('a', 'b')
  2. B. a,b a,b ['a', 'b'] ('a',)
  3. C. a,b a,b ['a', 'c'] ('a',)
  4. D. a,b a,b ('a', 'd') ('a',)

Correct answer: B. a,b a,b ['a', 'b'] ('a',)

Joining a string iterates over its characters, so ','.join('ab') is also 'a,b'. %s uses str() on the list, which shows brackets, and the one-item tuple keeps its trailing comma.

More Python Programming questions

Exams that ask this topic