0

Why does the last line return [0]?

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

12th Feb 2017, 4:32 PM
Vladislav Grishchenko
Vladislav Grishchenko - avatar
1 Resposta
+ 3
When slicing list, the start index (in your case 0) is inclusive and the end number (in your case 1) is exclusive. Therefore it only gets index 0. Examples... l= [1,2,3,4,5] l[0:3] #Equals 1,2,3 l[2:4] # Equals 3, 4
12th Feb 2017, 4:36 PM
~Q~
~Q~ - avatar