In this tutorial we will learn how to browse and display the elements of an array in Python.
You can simply use the for in to be able to read all the elements of an array.
equipements = ["Tablet", "Smartphone", "Computer"]
for x in equipements:
print(x)
Execution:
Tablet
Smartphone
Computer
The while can be used to browse in the same way as the for in.
list = [1, 2, 3, 4, 5, 6]
i = 0
# browse with the while
while i < len(lst):
print(list[i])
i = i+1
Runtime:
1
2
3
4
5
method range() can be combined with the for method to display the elements of an array in python.
range (start, end, pitch))
list = [3, 6, 32, 96, 43, 22]
for i in range(len(list)):
print(lst[i])
Runtime:
3
6
32
96
43
22
In a single line, It is possible to browse the table.
list=[3, 6, 7, 9, 6]
[print(x) for x in list]
Execution
3
6
7
9
6
It is possible to generate an array of integers in Python with the function numpy.arange() which creates a sequence of integers from 1 to n, then browse with the method numpy.nditer(array).
numpy.arange(start, end, pitch)
import numpy as np
n = np.arange(11)
for x in np.nditer(n):
print(x)
Runtime:
1
2
3
4
5
6
7
8
9
10
11
Please disable your ad blocker and refresh the window to use this website.