ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print('1.2.3.4'.rsplit('.', 1), 'x'.partition('='), 'a=b=c'.partition('='))
  1. A. ['1.2.3', '4'] ('x', 'x', '') ('a', '=', 'b=c')
  2. B. ['1.2.3', '4'] ('x', '', '') ('a', 'b', 'd')
  3. C. ['1.2.3', '4'] ('x', '', '') ('a', '=', 'b=c')
  4. D. ['1.2', '3.4'] ('x', '', '') ('a', '=', 'b')

Correct answer: C. ['1.2.3', '4'] ('x', '', '') ('a', '=', 'b=c')

rsplit with maxsplit=1 splits from the right, giving ['1.2.3', '4']. partition returns (before, separator, after) and gives empty strings when the separator is missing. It splits only at the first '='.

More Python Programming questions

Exams that ask this topic