Question:

What is the output of the following code snippet?

s='War and Peace by Leo Tolstoy'
print(s.partition("by"))

Show Hint

partition() returns a tuple of three items: text before, the separator, and text after.
Updated On: Oct 20, 2026
  • ('War and Peace ', 'by', ' Leo Tolstoy')
  • ['War and Peace ', 'by', ' Leo Tolstoy']
  • ('War and Peace ', ' Leo Tolstoy')
  • ['War and Peace ', ' Leo Tolstoy']
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Recall what partition() does:
s.partition(sep) finds the first sep in s. It returns a tuple of exactly three strings: the part before sep, sep itself, and the part after sep.

Step 2: Split the given string:
s = 'War and Peace by Leo Tolstoy' and the separator is "by".
The part before is 'War and Peace ' (with a space at the end).
The separator is 'by'.
The part after is ' Leo Tolstoy' (with a space at the start).

Step 3: Decide the type of the result:
partition() returns a tuple, so the output uses round brackets.
print() shows the tuple as ('War and Peace ', 'by', ' Leo Tolstoy').

Step 4: Why the other options are wrong:
(B) uses square brackets, which means a list. partition() never returns a list.
(C) has only two items. partition() always gives three, and it keeps the separator.
(D) is a list with two items, so it fails on both counts.

Final Answer:
The output is ('War and Peace ', 'by', ' Leo Tolstoy'), option (A).
Was this answer helpful?
0
0