Introduction
In Python, a list is a collection of items that are ordered and changeable. Sometimes, we need to access the last element of a list. In this challenge, you will write a function that returns the last element of a list.
In Python, a list is a collection of items that are ordered and changeable. Sometimes, we need to access the last element of a list. In this challenge, you will write a function that returns the last element of a list.
Write a function called last(lst)
that takes a list as an argument and returns the last element of the list.
def last(lst):
return lst[-1]
last([1, 2, 3]) ## 3
In this challenge, you learned how to write a function that returns the last element of a list. You can use the index -1
to access the last element of a list.