Python List reverse()
Python List reverse() is an inbuilt method in the Python programming language that reverses objects of the List in place.
There are no parameters.
The reverse() method does not return any value but reverses the given object from the list.
When anything other than list is used in place of list, then it returns an AttributeError
Example 1: Reverse a List
[6, 2, 1, 4, 3, 2, 1] ['a', 'a', 'd', 'c', 'b', 'a']
Example 2: Demonstrate the Error in reverse() Method
Traceback (most recent call last): File "/home/b3cf360e62d8812babb5549c3a4d3d30.py", line 5, in string.reverse() AttributeError: 'str' object has no attribute 'reverse'
Example 3: Practical Application
Given a list of numbers, check if the list is a palindrome.
Note: Palindrome-sequence that reads the same backward as forwards.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course