A collection of homogeneous elements in a single variable and contiguous memory locations is called an array. The elements in the array can be of any data type, but all elements present in the array should be homogeneous, that is, they should belong to the same data type.
An array is a special type of variable that actually stores multiple values or elements under the name of a single variable, with contiguous memory locations, accurately called "indexes".
The word index represents the plural form of index. The term index indicates the position of an element in an array. If there are n elements in an array, the position number of the element in the array or the index of the element starts from 0 and goes up to n – 1. The first element of the array has index 0, and the last element of the array is n – 1.
Step 1 - First, declare an array containing the corresponding elements or values so that the array size is not exceeded. Note that all elements considered in the array should be of the same data type.
Step 2 - In order to iterate over the entire array, starting from the first element with index "0" to the last element with index "n – 1", a loop must take The way the variable is incremented on each iteration means that the index of the elements starts from 0.
Step 3 - In the loop, considering the array with index " i ", print the elements of array[i] representing the element of the i-th index iteration. This operation must be performed within the loop itself so that the element is printed as soon as it is traversed.
In the following example, we will understand the process of printing an array.
arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] size = len(arr) print("The integral elements present in the array are: ") for i in range(0, size): print(arr[i])
The output of the above program is as follows -
The integral elements present in the array are: 1 2 3 4 5 6 7 8 9 10
The above is the detailed content of Python program prints an array. For more information, please follow other related articles on the PHP Chinese website!