I was practicing Phyton arrays, but I am stuck trying to print my array row by row.
When I use print
, my array is printed all in the same LINE.
I want like this:
Print 1st LINE of array
Print second LINE of array below 1st
Print third LINE of array below second
.
.
.
Print last LINE of array
Asked
Active
Viewed 528 times
-2

Tomerikoo
- 18,379
- 16
- 47
- 61
-
https://www.geeksforgeeks.org/print-lists-in-python-4-different-ways/ refer this for your learning – Mukul Kumar Jul 20 '22 at 04:46
-
1Does this answer your question? [Python print array with new line](https://stackoverflow.com/questions/13893399/python-print-array-with-new-line) – Paul Kim Jul 20 '22 at 04:46
-
Does this answer your question? [How to print a 2D list so that each list is on a new line with a space, without any "" or \[\]](https://stackoverflow.com/questions/47582312/how-to-print-a-2d-list-so-that-each-list-is-on-a-new-line-with-a-space-without) – Tomerikoo Jul 20 '22 at 05:30
-
Welcome to Stack Overflow. I can't understand what you mean. Please read [ask] and [mre], and make sure you can show an exact example: exactly what is in the list beforehand (show code that we can copy and paste in order to create exactly the right list)? Exactly what should be printed (show what you expect to see in the terminal window, by [formatting](https://stackoverflow.com/help/formatting) the text like code)? – Karl Knechtel Jul 20 '22 at 05:54
1 Answers
-1
you can use for loops:
Example 1:
from array import *
array_letters = array('u', ['a', 'b', 'c'])
for letter in array_letters:
print(letter)
Output:
a
b
c
Example 2
from array import *
array_vals = array('i', [8, 2, 6, 4, 5])
newArr = array(array_vals.typecode, (num*num for num in array_vals))
for i in newArr:
print(i)
Output:
64
4
36
16
25

Vin Bolisetti
- 45
- 6