In this program, we will take a user input as a list and reverse a list with reversed and reverse methods with the help of the below-given steps.
Table of Contents
Reverse a list:
Method 1 : Using reversed().
Steps to solve the program
- Take a list as input.
- Reverse a list using the reversed() function.
#Input list
list1 = [2,3,7,9,3,1]
#Using reversed method
print("Using reversed: ",list(reversed(list1)))
Output :
Using reversed: [1, 3, 9, 7, 3, 2]
Method 2 : Using reverse()
Steps to solve the program
- Take a list as input.
- Print the given list in reverse order using reverse().
#Input list
list1 = [2,3,7,9,3,1]
#using reverse method
list1.reverse()
print("Using reverse: ", list1)
Output :
Using reverse: [1, 3, 9, 7, 3, 2]
Related Articles
Python program to copy or clone one list to another list.
Python program to return True if two lists have any common member.
Python program to print a specific list after removing the 1st, 3rd, and 6th elements from the list.
Python program to remove negative values from the list.
Python program to get a list of all elements which are divided by 3 and 7.
Python program to check whether the given list is palindrome or not.