Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
18
8
116
12.2K
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr A) [25, 10] Negative step with skip! › [::−2] = start:stop:step › step=-2 means: go backwards, take every 2nd element › Start at end: 25 › Jump back 2 positions: 10 › Result: [25, 10] For beginners: Negative step goes right-to-left
English
1
0
14
405
Abhishek Dubey
Abhishek Dubey@On_Akdy·
@PythonPr A) [25,10] Because you're just reversing the list and skipping the even indexed element if you're looking from left to right, at the same time.
English
0
0
2
272
Biel Men
Biel Men@BielMenHaha·
@PythonPr None, because the slice begin at index 0, but it can't go below index 0, so will be a empty list
English
1
0
2
436
Tony
Tony@tonybnya·
@PythonPr we have sequence[start:stop:step] step is negative, so the slice starts from the end the slice moves backwards by 2 steps each time start & stop are omitted, so we go all the way to the beginning, so: A. [25, 10]
English
0
0
2
166
Omo Yewa
Omo Yewa@AceKelm·
@PythonPr Answer is A. [25, 10]. Brief Explanation: That's a negative list step. Starting from the right is 25, jumping two steps to the left is 10.
English
0
0
1
135
Ada
Ada@Adatwice·
@PythonPr [25, 10] I am getting good at this!
English
0
0
1
99
C4liph3r
C4liph3r@AlimiKaleef·
@PythonPr [25, 10] Iterate through the list in a reverse form and omit every second item.
English
0
0
0
4
Paylaş