To get the last element in a Python list, you can use negative indexing or the `[-1]` index.
In this example,
numbers
with integer elements.[-1]
.numbers = [10, 20, 30, 40, 50]
last_element = numbers[-1]
print(f'Last element is: {last_element}')
Last element is: 50
In this example,
names
with string elements.[-1]
.names = ['Alice', 'Bob', 'Charlie', 'David']
last_element = names[-1]
print(f'Last element is: {last_element}')
Last element is: David
In this tutorial, we learned How to get Last Element in a List in Python language with well detailed examples.