In this program, we get a little awareness regarding reversing an array in Python. We are reversing an array using for loop although, we have different methods to solve this program.
This program describes the reversing of an array. We can solve reversing an array in different methods like for loop, reverse() method, reversed() method, using slicing, using recursion, using swapping and so on. In this program, we are using for loop. First, we will initialize an array named s and considering our convenient array elements here, we are using array elements as [1,2,3,4,5]. After, this we are using for loop range of 0 to the length of an array and printing the array.
Again, we are considering for loop with the length of an array with a decremented length of 1 and printing the array of elements in each iteration. For example, if an original array is [2,4,6,8] we obtain the reversing array as [8,6,4,2]. The Python language does not support array data structure. Instead, it has in-built list structures that are easy to use. There are many user-defined and in-built methods in Python to reverse an array. An array is a data structure that is used to store homogeneous elements in order and stored elements are identified by an index value or a key.
Submitted by YANIGANTI SUCHITRA (Suchitra)
Download packets of source code on Coders Packet
Comments