0

why the answer of this code is [0, 1, 4, 9, 16, 25, 36, 49, 64] and not [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] and iam remember that -1 starts from the last no. in the list , then why the answer is not include 81????

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

4th Aug 2016, 5:31 PM
Ahmed Kamal
Ahmed Kamal - avatar
3 Answers
+ 1
first number is always 0. Try to print(squares[0:-1])
4th Aug 2016, 7:43 PM
Katarzyna Surma
Katarzyna Surma - avatar
+ 1
by standard the python dont include the last index , just the first one, this serves for tuples too. then, ever you slice a list, the second index won't be returned.
9th Aug 2016, 7:01 PM
AntĂ´nio Alexandre Neto
AntĂ´nio Alexandre Neto - avatar
0
But answer will be 1,4,9,16,25,36,49,64
9th Aug 2016, 5:49 PM
Ashutosh Mishra
Ashutosh Mishra - avatar