why [::-3] | Sololearn: Learn to code for FREE!
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]

6th May 2017, 2:24 PM
Gytree
Gytree - avatar
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.
6th May 2017, 3:38 PM
Tob
Tob - avatar
+ 3
but should not be [0]?
6th May 2017, 3:51 PM
Gytree
Gytree - avatar
+ 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]
6th May 2017, 5:22 PM
Gytree
Gytree - avatar
+ 1
I got it! the first item is included
6th May 2017, 3:53 PM
Gytree
Gytree - avatar
+ 1
print(b) [1] ? a = [ 0, 1, 2, 3 ] -4 -3 -2 -1
6th May 2017, 5:14 PM
Jon Lassleben
Jon Lassleben - avatar