Python Program to print array elements in reverse order


In this program, you will learn how to print array elements in reverse order in Python.


a = array('i', [2, 3, 4, 5])

Example: How to print array elements in reverse order in Python

import array as arr

a = arr.array('i', [])

se = sod = 0

k = int(input("Enter size of array:"))
for i in range(0, k):
    num = int(input("Enter %d array element:" % (i + 1)))
    a.append(num)

print("Array list:", a)

print("List in reverse order:", end="")
for i in range(a.__len__() - 1, -1, -1):
    print(a[i], end=" ")

Output:

Enter size of array:4
Enter 1 array element:10
Enter 2 array element:20
Enter 3 array element:30
Enter 4 array element:40
Array list: array('i', [10, 20, 30, 40])
List in reverse order:40 30 20 10

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.