What is the array reverse() method in Python?

Overview

An array in python is used to store multiple values of the same datatype in a single variable.

The reverse() function is simply used to reverse the order of the items in a given array.

Syntax

array.reverse()

Parameter value

The reverse() method takes no parameter value.

Return value

The reverse() function returns the reversed array as an output.

Example

# importing the array module
import array as arr
# creating an integer data type array
x = arr.array('i', [1,2,3,4,5,6,7])
# reversing the arraay using the reverse method
x.reverse()
# Printing the reversed array
print(x)

Free Resources