Python: Reverse the order of the items in the array
3. Reverse the Order of Items in an Array
Write a Python program to reverse the order of the items in the array.
Pictorial Presentation:

Sample Solution:
Python Code :
from array import *
array_num = array('i', [1, 3, 5, 3, 7, 1, 9, 3])
print("Original array: "+str(array_num))
array_num.reverse()
print("Reverse the order of the items:")
print(str(array_num))
Sample Output:
Original array: array('i', [1, 3, 5, 3, 7, 1, 9, 3]) Reverse the order of the items: array('i', [3, 9, 1, 7, 3, 5, 3, 1])
For more Practice: Solve these Related Problems:
- Write a Python program to reverse an array in-place using slicing with a negative step.
- Write a Python program to create a reversed copy of an array using the reversed() function and then convert it back to an array.
- Write a Python program to implement a function that reverses an array by iterating over it in reverse order without using built-in functions.
- Write a Python program to reverse an array using a for-loop to append elements from the end to a new array.
Go to:
Previous: Write a Python program to append a new item to the end of the array.
Next: Write a Python program to get the length in bytes of one array item in the internal representation.
Python Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.