+ 2

I didn't understand that code below

squares [0,1,4,9,16,25,36,49,64,81] print (squares [::2])

29th Jun 2021, 9:06 AM
Ahmed Jezi
2 Respostas
+ 6
indexing is [start:stop:step] The step is 2 so it'll print a list showing every other value in the list. (default value for step is 1)
29th Jun 2021, 9:08 AM
Slick
Slick - avatar
+ 3
slice default start index is 0, default end index (not included) is list length, step is 2... meaning the printed list will have the original list values at indexes 0, 2, 4, 6, 8... so output is: [0,4,16,36,64]
29th Jun 2021, 10:22 AM
visph
visph - avatar