Very simple question, I have a list like so:
a = [0,1,2,3,4,5,7,8]
and I need to get the last item in that list as a float or an integer. If I do:
print a[0], a[4]
I get 1 5
, which is fine, but if i try to retrieve the last item with:
print a[-1:]
I get the list [8]
instead of the number 8
. I know that I could just use print a[len(a)-1]
but it feels kind of overkill and now I also have the doubt of why is a[-1:]
returning a list instead of an element?