arrays - How to get the last number from list in python -
this question has answer here:
- getting last element of list in python 11 answers
suppose have list
a = [0.0021, 0.12, 0.1224, 0.22]
i have extract last number above list, answer should 0.22
without using a[3]
, because number of elements in list keep changing.
you're talking list. arrays in python numpy.arrays. different data structure.
you can achieve want this:
>>> array = [0.0021, 0.12, 0.1224, 0.22] >>> array[-1] 0.22 >>>
negative indexing starts @ end of list, array[-1]
last element in list, array[-2]
second last , forth.
Comments
Post a Comment