Advertisements
Advertisements
Question
Select the correct output of the following code:
event="G20 Presidency@2023"
L=event.split(' ')
print (L[::−2])
Options
'G20'
['Presidency@2023']
['G20']
'Presidency@2023'
MCQ
Solution
['Presidency@2023']
Explanation:
The split() function separates a string based on a delimiter character and returns a list of its components. event.Split() generates a list containing ['G20', 'Presidency@2023']. Split the string on'' and print the result (L[::−2]). To get ['Presidency@2023'], return values from the list backward and skip by 2.
shaalaa.com
Is there an error in this question or solution?