How to Reverse A List in Python
Posted on: February 24, 2021 by Ariessa Norramli
In this article, you will learn how to reverse a list in python in Python.
Let’s say you have a list named ‘a’ with value [1, 2, 3, 4, 5].
a = [1, 2, 3, 4, 5]
In order to reverse a list, you can use the list.reverse()
method.
a = [1, 2, 3, 4, 5]
# Reverse the list named 'a'
a.reverse()
print(a)
# => [5, 4, 3, 2, 1]
Note: The list.reverse()
method functions by reversing the elements in a list.
Share on social media
//