Program to reverse a list in Python
In the python programming tutorial, we are going to learn
-
program to reverse a list in python
Program to reverse a list in Python
The python program to reverse a list to reverse a list is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
marks=[78,56,98,39,55,91,72]
reversed_marks = marks[::-1]
print(reversed_marks)
The output of the python program to reverse a list is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
[72, 91, 55, 39, 98, 56, 78]
Few important tips about the program
1. In the given program, we have reversed the given list using the concept of negative indexing and assignment in python.
2. Python also provides a .reverse() method for lists which reverses a list in place. It doesn't assigns the reversed list to a new list.
3. The reversed() function takes a list as an argument and reverses it. It doesn't a return a list but a reverseiterator object.
Program to reverse a list in python snapshot:
This wraps up our session on program to reverse a list in python.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Jun 19,2022