ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
s = 'key=value=end'
print(s.partition('='), s.rpartition('='), 'a  b'.split(' '))
  1. A. ('key', '=', 'value') ('key=value', '=', 'end') ['a', 'b']
  2. B. ('key', '=', 'value=end') ('key=value', '=', 'end') ['a', '', 'b']
  3. C. ('key', '=', 'value=end') ('key=value', '=', 'end') ['a', 'bb']
  4. D. ('key', '=', 'value') ('key=value', '=', 'end') ['b']

Correct answer: B. ('key', '=', 'value=end') ('key=value', '=', 'end') ['a', '', 'b']

partition splits at the first separator and rpartition at the last. split with an explicit space keeps the empty field between two spaces.

More Python Programming questions

Exams that ask this topic