ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('abc'.partition('x'), 'a=b=c'.partition('='), 'a=b=c'.rpartition('='))
  1. A. ('abc', 'x', '') ('a', '=', 'b=c') ('a=b', '=', 'c')
  2. B. ('abc', '', '') ('a', '=', 'b') ('a=b', '=', 'c')
  3. C. ('abc', '', '') ('a', '=', 'b=c') ('a=b', '=', 'c')
  4. D. ('abc',) ('a', 'b', 'c') ('a=b', '=')

Correct answer: C. ('abc', '', '') ('a', '=', 'b=c') ('a=b', '=', 'c')

partition() returns three parts, with empty separators when the text is missing. partition splits at the first '=' and rpartition splits at the last, which is why the two results differ.

More Python Programming questions

Exams that ask this topic