Reputation: 129
Can anyone explain how works Negative index of 0?
x = [2, 3, 5, 6]
print(x[-0])
output: 2
Upvotes: 0
Views: 27
Reputation: 365
What you enter as the index gets evaluated. For example :
x = [2, 3, 5, 6]
print(x[2 - 1])
It prints 3
because it is evaluated as print(x[1])
. Here you used -0
so it is the same as 0
.
Upvotes: 1