Advertisements
Advertisements
Question
What is the output of the following code snippet?
s=‘War and Peace by Leo Tolstoy’
print(s.partition(“by”))
Options
('War and Peace ', 'by', ' Leo Tolstoy')['War and Peace ', 'by', ' Leo Tolstoy']('War and Peace ', ' Leo Tolstoy')['War and Peace ', ' Leo Tolstoy']
MCQ
Advertisements
Solution
('War and Peace ', 'by', ' Leo Tolstoy')
Explanation:
s.partition(“by”) returns a 3-tuple: (text before, separator, text after). For the given string, it produces ('War and Peace’, ‘by’, ‘Leo Tolstoy’); note that the spaces remain with the surrounding parts.
shaalaa.com
Is there an error in this question or solution?
