- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print the elements of an array in reverse order
When it is required to print the elements of an array in reverse order, the list can be iterated over from the end.
Below is a demonstration of the same −
Example
my_list = [21, 32, 43, 54, 75] print("The list is : ") for i in range(0, len(my_list)): print(my_list[i]) print("The list after reversal is : ") for i in range(len(my_list)-1, -1, -1): print(my_list[i])
Output
The list is : 21 32 43 54 75 The list after reversal is : 75 54 43 32 21
Explanation
A list is defined, and is displayed on the console.
The list is iterated over, and displayed.
It is reversed by iterating it from the last element.
Every element is displayed on the console.
Advertisements