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.
last([1, 2, 3]) ## 3
last(['apple', 'banana', 'cherry']) ## 'cherry'
last([]) ## None
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.