Iterating an array with index and element in Python

Here in this post you will know about how to iterate an array with index and element in python.

PYTHON ARRAY ITERATION

 

To iterate an array in python we use looping statements like for loopWe can start with defining an array.

Here’s an example for defining an array,

#defining an array 
#syntax
Array_name=[arr_value1,arr_value2,.,....]
#example
arr1=[1,3,5,7,9]
arr2=[2,4,6,8,10]

After defining an array, iterate it with an index or  an element and a for loop.
Below you can find an example to declare an for loop to iterate an array with an index

#syntax
for <index_name> in <range (or) array_size>
#example 1
for index in range(start value, stop value)
#example 2
for i in range(Start value, stop value, step value)
#example 3 
for i in array_name

Using these an above examples you can gain knowledge on how to iterate an array with index and element in python. Below you can find an complete example for the topic.

#complete example for iterating an array with an index and element in python
#defining an array 
SUVs=['Creta','Fortuner','Duster']
#defining for loop with element
for i in SUVs:
    print(i)

The output of above code is as follows,

Creta
Fortuner
Duster

Thank you for reading this post…

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top