Test Index
Python Revision Tour
© examsnet.com
Question : 59 of 102
Marks:
+1,
-0
Select the correct output of the following code :
event="G20 Presidency@2023"L=event.split(' ')print(L[::-2])[CBSE 2024 Set 4]
Solution:
Solution:
event.split(' ') splits at the space:L = ['G20', 'Presidency@2023']L[::-2] starts from the last element and moves backwards in steps of 2:index 1 gives 'Presidency@2023'; the next index would be -1 (before the start), so the slice stops.Result: ['Presidency@2023']Key point: Slicing a list always gives a list, so the output has square brackets.Answer:Option B (['Presidency@2023'])© examsnet.com
Go to Question: