Test Index

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

© examsnet.com
Question : 94 of 102
Marks: +1, -0
Select the correct output of the code :
S="Amrit Mahotsav @ 75"
A=S.split(" ",2)
print(A)
[CBSE 2023 Compartment]
Solution:  
Concept:
str.split(sep, maxsplit) splits the string at sep at most maxsplit times and returns a list; the rest of the string stays as the last item.
Explanation:
With maxsplit = 2, only the first two spaces are used:
"Amrit" | "Mahotsav" | "@ 75" (the third space is not split).
Output:
['Amrit', 'Mahotsav', '@ 75']
split() always returns a list (square brackets), never a tuple, so options (A) and (C) are out; (D) would need all three spaces to be split.
Answer:
Option B (['Amrit', 'Mahotsav', '@ 75'])
© examsnet.com
Advertisements
Go to Question: