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]
3 odpowiedzi
+ 1
first number is always 0. Try to print(squares[0:-1])
+ 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.
0
But answer will be 1,4,9,16,25,36,49,64