There is the possibility to use positions reversed, array[-1], array[-2], and so on. Example:
array = [1,2,3,4,5]
print(array[-1])
#O retorno será '5'
print(array[-2])
#O retorno será '4'
So:
mod_elasticidade = tensao[-1]
If you want to do it using the function len()
also you can, you were getting error, because the function len()
returns the number of elements counting from 1:
array = [1,2,3,4,5]
print(len(array))
#O retorno será '5'
Already positions, are counted from 0, and in this example range from 0 to 4:
array = [1,2,3,4,5]
#A posição 0 é o 1, a 1 é o 2, e assim em diante
print(array[0])
#O retorno será '1'
print(array[4])
#O retorno será '5'
So:
ultimo = len(tensao)-1 # -1, para reduzir essa diferença
mod_elasticidade = tensao[ultimo]
When the answers provided answer your question to your satisfaction, consider marking them as accepted.
– jsbueno
Possible duplicate of How to capture the last element of a Python list?
– Woss