ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
s = 'a\tb\nc'
print(len(s), s.split(), s.split('\n'), repr(s.split()[0]))
  1. A. 5 ['a', 'b', 'c'] ['a\tb', 'c'] 'a'
  2. B. 4 ['a', 'b', 'c'] ['a\tb', 'c'] 'a'
  3. C. 5 ['a', 'b'] ['a\tb', 'c'] 'a'
  4. D. 5 ['a', 'b', 'c'] ['a', 'b\nc'] 'a'

Correct answer: A. 5 ['a', 'b', 'c'] ['a\tb', 'c'] 'a'

The string has five characters: a, tab, b, newline and c. split() with no argument also splits on the tab and newline, and split('\n') splits only on the newline.

More Python Programming questions

Exams that ask this topic