arrays - How to get the last number from list in python -


this question has answer here:

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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -