Select the correct output of the code:
a = "Year 2022 at All the best"
a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)
(a) Year . 0. at All the best
(b) Year 0. at All the best
(c) Year . 022. at All the best
(d) Year . 0. at all the best
Answer:
So, the correct answer is (a).
Explanation:
The split( ) method in python splits a string into a list . The separator for splitting the string is given in the parentheses of the split( ) method.
In the given code, the string ‘a’ is split into 3 and each split is stored as a list item in a and the separator for splitting the string is 2 . This means that the string is split every time a 2 is encountered in the string.
So the list becomes
{“Year ” , ”0” , “ at All the best”}
Finally, all three list items are printed with a ‘.’ in between.
Therefore, the output is “Year . 0. at All the best”