How can Python print an array?
To print an array, you can use the print() function to print the entire array, or you can use a loop to print each element of the array one by one. Here are examples of both methods.
- output()
arr = [1, 2, 3, 4, 5]
print(arr)
Output:
[1, 2, 3, 4, 5]
- Print each element of the array one by one in a loop.
arr = [1, 2, 3, 4, 5]
for element in arr:
print(element)
Output:
1
2
3
4
5