ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
s = "a  b\tc\n"
print(s.split(), len(s.split(" ")), len(s.strip(" ")), len(s.strip()))
  1. A. ['a', 'b', 'c'] 2 7 6
  2. B. ['a', 'b', 'c'] 3 5 4
  3. C. ['a', 'b', 'c'] 3 7 6
  4. D. ['a', 'b\tc'] 3 7 6

Correct answer: C. ['a', 'b', 'c'] 3 7 6

split() with no argument splits on runs of any whitespace. split(' ') splits on each single space, giving 3 pieces with an empty string between the two spaces. strip(' ') removes only spaces (none at the ends, so length 7), while strip() also removes the trailing newline (length 6).

More Python Programming questions

Exams that ask this topic