Monday, 9 October 2017

What's the significance of negative indices in python?

I was wondering why negative indices in python are so
important - are there any applications? I could just use



my_list[len(my_list) -
1]



to find
the last element of my_list. Why do we need



class="lang-py
prettyprint-override">my_list[-1]


To
find the last element?



EDIT:
It's not
that I don't understand what my_list[-1] means, I want to know
where this might be used.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...