A Suresh
A Suresh

Reputation: 129

List negative indexing of 0; x[-0]

Can anyone explain how works Negative index of 0?

x = [2, 3, 5, 6]

print(x[-0])

output: 2

Upvotes: 0

Views: 27

Answers (1)

Alexandre Marcq
Alexandre Marcq

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

Related Questions