Definition:
If you need to change the order of values in a list, this method reverses the list.
Note: This function reverses the current order of the list.
Now you will clearly understand the method through the flowchart .
List → a = [10, 20, 30]
Index : 0 1 2
↓ ↓ ↓
Value : 10 20 30
Method → a.reverse()
After Reverse → [30, 20, 10]
Index : 0 1 2
↓ ↓ ↓
Value : 30 20 10
Syntax
list_name.reverse()
Example:
a = [10, 20, 30]
a.reverse()
print(a)
Output:
Exercise
Reverse the list a = [5, 10, 15] using Python.
