Question:

Question: Select the correct output of the following code:

event = "G20 Presidency@2023"
L = event.split(' ')
print(L[::-2])
    

Show Hint

Use list[::-step]} to reverse or skip elements in a list. The step size determines how elements are selected.
Updated On: Jan 21, 2025
  • 'G20'
     

  • 'Presidency@2023' 
     

  • 'G20'
     

  • 'Presidency@2023'
     

Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

<div class="question">
   <strong>Question:</strong> The split() method divides the string "G20 Presidency@2023" into a list of substrings based on spaces, resulting in: 
   <pre><code>
L = ["G20", "Presidency@2023"]
   </code></pre>
   The slicing operation L[::-2] works as follows: 
   <ul>
       <li>[::-2] reverses the list and selects every second element.</li>
       <li>Starting from the end, L[::-2] picks "G20".</li>
   </ul>
   Thus, the output is: ['G20'].
</div>
 

Was this answer helpful?
0
0