Test Index
CBSE Class 12 Computer Science 2026 Paper Set 4
© examsnet.com
Question : 4 of 37
Marks:
+1,
-0
What is the output of the following code snippet ?
s='War and Peace by Leo Tolstoy'print(s.partition("by"))
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
Go to Question: