Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 4 of 102
Marks: +1, -0
What is the output of the following code snippet ?
s='War and Peace by Leo Tolstoy'
print(s.partition("by"))
[CBSE 2026 Set 4]
Solution:  
Concept:
str.partition(sep) splits the string at the first occurrence of sep and always returns a tuple of three strings: (part before sep, sep itself, part after sep).
Explanation:
Before 'by': 'War and Peace ' (with the trailing space)
Separator: 'by'
After 'by': ' Leo Tolstoy' (with the leading space)
Output:
('War and Peace ', 'by', ' Leo Tolstoy')
Key point: partition() returns a tuple and keeps the separator; split() returns a list and drops it.
Answer:
Option A (('War and Peace ', 'by', ' Leo Tolstoy'))
© examsnet.com
Advertisements
Go to Question: