Negative numbers mean that you count from the right instead of the left. So, list[-1] refers to the last element, list[-2] is the second-last, and so on.
Negative numbers mean that you count from the right instead of the left. So, list[-1] refers to the last element, list[-2] is the second-last, and so on.
List indexes of -x mean the xth item from the end of the list, so n[-1] means the last item in the list n. Any good Python tutorial should have told you this.
It's an unusual convention that only a few other languages besides Python have adopted, but it is extraordinarily useful; in any other language you'll spend a lot of time writing n[n.length-1] to access the last item of a list.
What's the use of negative indexing?
Negative indexing in Python - Python - Data Science Dojo Discussions
What is a Negative Index? - TestMu AI Community
Negative/signed integer indexing: yay or nay?
Videos
Very noob question, but why would you need to use a negative index over the positive one? Why would I use [-3] over just using [2] for example?
I googled this but couldn't really find an explanation anywhere