This content originally appeared on CodeSource.io and was authored 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.
The post How to Reverse A List in Python appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-24T10:25:30+00:00) How to Reverse A List in Python. Retrieved from https://www.scien.cx/2021/02/24/how-to-reverse-a-list-in-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.