event = "G20 Presidency@2023"
L = event.split(' ')
print(L[::-2])
'G20'
'Presidency@2023'
'G20'
'Presidency@2023'
<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>
myStr[:4]
extracts the first 4 characters, which are "MISS"
.myStr[-5:]
extracts the last 5 characters, which are "SIPPI"
."#"
in between, resulting in "MISS#SIPPI"
.Consider the following Python statement:
F = open('CONTENT.TXT')
Which of the following is an invalid statement in Python?