+ 2

What is the Output of this Code, And explain why it Outputs from 1 to 64

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

3rd Mar 2022, 5:35 AM
David Mphande
David Mphande - avatar
1 Réponse
+ 5
List slicing notation: [start:stop:step] It includes start value while stop isn't included. Also, index value of -1 gives the last element of the list. So, [1:-1] is same as [1:9]. Hence, it returns [1,.....,64]
3rd Mar 2022, 5:45 AM
Simba
Simba - avatar