listA[-1]
is the shortest and Python way.
Besides that,
To find the nth element in the background,
listA[-n]
You can write it like this.
When you want to change the last element,
listA[-1] = 6
You can change it by designating it together
listA = [1,2,3,4,5]
listA[-1] = "Change"
print listA
[1, 2, 3, 4, 'change!']
© 2024 OneMinuteCode. All rights reserved.