ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
s = "a,b,,c,"
print(len(s.split(",")), len(s.split()), s.rsplit(",", 2)[0], s.partition(";")[0] == s)
  1. A. 3 1 a,b, True
  2. B. 5 1 a True
  3. C. 5 1 a,b, False
  4. D. 5 1 a,b, True

Correct answer: D. 5 1 a,b, True

split(',') keeps empty strings, giving ['a', 'b', '', 'c', ''] (5 items); split() with no separator finds no whitespace, so one item. rsplit with maxsplit 2 splits only the last two commas. partition with an absent separator returns (s, '', '').

More Python Programming questions

Exams that ask this topic