New course! Every coder should learn Generative AI!
Try a free lesson+ 3
why [::-3]
why b is [3,0] a=[0,1,2,3] b = a[::-3]
5 Answers
+ 4
[::-3] lets you go through the list backwards with step size 3.
The last element in a is 3. Go three steps back and you get 0. There are no elements in front of 0, so [3,0] is the whole of b.
+ 3
but should not be [0]?
+ 3
1) first save de initial item (-1) in this case 3
[3]
2) 3 step back is -1 -3 = -4 save -4 in this case 0
[3,0]
+ 1
I got it! the first item is included
+ 1
print(b)
[1]
?
a = [ 0, 1, 2, 3 ]
-4 -3 -2 -1