You could join the strings with a newline, and print the resulting string:

print "\n".join(op)
Answer from Sebastian Paaske Tørholm on Stack Overflow
🌐
AskPython
askpython.com › python › array › print-an-array-in-python
How to Print Arrays in Python? - AskPython
July 5, 2026 - To print arrays in Python, you can use the print() function directly for simple output or implement loops for formatted display. This guide covers both
Discussions

python - print list elements line by line - is it possible using format - Stack Overflow
I very like quite new Python convention to print things with .format() Is it possible using it to print element line by line. Assuming of course number of elements is unknown. Working example wil... More on stackoverflow.com
🌐 stackoverflow.com
python - Printing an int list in a single line python3 - Stack Overflow
Yes that is possible in Python 3, just use * before the variable like: ... This will print the list separated by spaces. (where * is the unpacking operator that turns a list into positional arguments, print(*[1,2,3]) is the same as print(1,2,3), see also What does the star operator mean, in a function call?) ... Sign up to request clarification or add additional context in comments. ... Save this answer. ... Show activity on this post. ... The syntax i in array ... More on stackoverflow.com
🌐 stackoverflow.com
How do I print every 3 values of an array in new lines?
for i in range(0, len(row), 3): print(row[i:i+3]) More on reddit.com
🌐 r/learnpython
6
1
July 5, 2022
python - How to print an array row by row? - Stack Overflow
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 secon... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

How do I print an array in Python without brackets?
Pass the elements to print() individually with a separator, or use ' '.join() for a list of strings. For numbers, build the output string with a loop and an f-string. For NumPy, np.set_printoptions(formatter={'int': lambda x: str(x)}) strips the brackets.
🌐
askpython.com
askpython.com › python › array › print-an-array-in-python
How to Print Arrays in Python? - AskPython
What is the difference between printing a list and a NumPy array?
A Python list prints with commas between elements like [1, 2, 3]. A NumPy array prints without commas like [1 2 3]. NumPy also auto-aligns multi-dimensional arrays without any extra work.
🌐
askpython.com
askpython.com › python › array › print-an-array-in-python
How to Print Arrays in Python? - AskPython
How do I print a 2D array as a grid with aligned columns?
Loop over rows and inner elements, formatting each value with a fixed-width f-string like f'{value:4}'. This works for both lists and NumPy arrays and gives you the same aligned grid NumPy produces automatically.
🌐
askpython.com
askpython.com › python › array › print-an-array-in-python
How to Print Arrays in Python? - AskPython
🌐
Quora
quora.com › How-do-you-print-each-element-in-an-array-in-Python
How to print each element in an array in Python - Quora
Answer (1 of 4): Python print() can print all the elements ts in and array with the * operator. [code]myArray = [1,2,3,4,5] print[*myArray,sep='/n') [/code]Output; [code]1 2 3 4 5 [/code]Python also lets you iterate through each element in a list or numpy array: [code]myArray = [“Hello”...
🌐
Finxter
blog.finxter.com › python-one-line-array
Python One Line Array – Be on the Right Side of Change
August 28, 2020 - lst = [8, 2, 6, 4, 3, 1] # Filter all elements <8 small = [x for x in lst if x<8] print(small) # Filter all even elements even = [x for x in lst if x%2==0] print(even) # Filter all odd elements odd = [x for x in lst if x%2] print(odd) ... This is the most efficient way of filtering an array and it’s also the most Pythonic one. ... Python programmers will improve their computer science skills with these useful one-liners.
Top answer
1 of 8
47

If you are using Python 3.x and your intention is to just printing the list of elements, one in each line, then you can use print function itself, like this

my_list = [1, 2, 3, 4]
print(*my_list, sep="\n")

*my_list simply unpacks the list elements and pass each one of them as parameters to the print function (Yes, print is a function in Python 3.x).

Output

1
2
3
4

If you are using Python 2.x, then you can just import the print function from the future like this

from __future__ import print_function

Note: This import should be the first line in the file.

2 of 8
12

You can use the string formatter on really any kind of string, including multi-line string. So of course, if you had a format string '{}\n{}\n{}' you could pass three items to it, and they would be all placed on separate lines.

So with a dynamic number of elements you want to print, all you need to do is make sure that the format string contains the same number of format items too. One way to solve this would be to construct the format string dynamically. For example this:

'\n'.join('{}' for _ in range(len(my_list))).format(*my_list)

So you essentially create a format string first, by having a generator produce one format item {} per element in my_list, and joining these using a newline character. So the resulting string looks something like this: {}\n{}\n…\n{}\n{}.

And then you use that string as the format string, and call format on it, passing the unpacked list as arguments to it. So you are correctly filling all spots of the format string.

So, you can do it. However, this is not really a practical idea. It looks rather confusing and does not convey your intention well. A better way would be to handle each item of your list separately and format it separately, and only then join them together:

'\n'.join('{}'.format(item) for item in my_list)

As for just printing elements line by line, of course, the more obvious way, that wouldn’t require you to build one long string with line breaks, would be to loop over the items and just print them one-by-one:

for item in my_list:
    print(item)

    # or use string formatting for the item here
    print('{}'.format(item))

And of course, as thefourtheye suggested, if each loop iteration is very simple, you can also pass the whole list to the print function, and set sep='\n' to print the elements on separate lines each.

Find elsewhere
🌐
Java2Blog
java2blog.com › home › python › python array › print array in python
Print Array in Python - Java2Blog
October 18, 2021 - *list simply unpacks the list and pass it to print function. Below is the Python code given: ... Here, for loop is used to iterate through every element of an array, then print that element.
🌐
Stack Overflow
stackoverflow.com › questions › 73046081 › how-to-print-an-array-row-by-row
python - How to print an array row by row? - Stack Overflow
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) ... Sign up to request clarification or add additional context in comments.
🌐
WsCube Tech
wscubetech.com › resources › python › programs › print-array
Python Program to Print an Array (5 Methods)
1 month ago - Learn how to print an array in Python using 5 different methods. Explore approaches with for loops, print(), range(), and more with examples. Read now!
🌐
GeeksforGeeks
geeksforgeeks.org › print-lists-in-python-4-different-ways
Print lists in Python - GeeksforGeeks
April 8, 2025 - Now, let's see how to use print function for multi-line printing. This can easily be done using multiline string i.e. three single quotes ''' Geeksforgeeks ''' . Let's see different examples to see the demonstration for the same. ... The python print() function as the name suggests is used to print a python object(s) in Python as standard output.
🌐
Plain English
python.plainenglish.io › 3-ways-to-print-list-elements-on-separate-lines-in-python-815454bb2cd4
3 Ways to Print List Elements on Separate Lines in Python | Python in Plain English
July 16, 2024 - New Python content every day. Follow to join our 3.5M+ monthly readers. ... Dr. Ahmed Al-Jaishi ... I often want to print the elements of a list. Unfortunately, the print function packs the list elements and often makes the output unreadable(e.g., Figure 1). Below are three ways to print list elements so that each element appears on a new line.
🌐
Plain English
plainenglish.io › home › blog › python › 3 ways to print list elements on separate lines in python
3 Ways to Print List Elements on Separate Lines in Python
April 11, 2022 - print("\n".join(results)) # Element number: 1, Result: 212 # Element number: 2, Result: 134 # Element number: 3, Result: 151 # Element number: 4, Result: 104 # Element number: 5, Result: 174 · I hope you found these code snippets helpful. Thank you for reading! ... A practical guide to the Python libraries that cover data, web APIs, testing, and automation — with when to use each one.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to print an array in python
5 Best Ways to Print an Array in Python - Be on the Right Side of Change
February 26, 2024 - The pprint() function, part of Python’s pretty-print library, provides a cleaner display of the array by managing the formatting.
🌐
Java2Blog
java2blog.com › home › python › print elements of list on separate lines in python
Print Elements of List on Separate Lines in Python [5 ways] - Java2Blog
November 25, 2022 - Both of these, when combined together, can implement the task at hand. When we specify the sep parameter value as a newline character (\n), it prints all the elements in different lines. The following code uses the * symbol and the sep parameter to print elements of a list on separate lines ...
🌐
FavTutor
favtutor.com › blogs › print-list-python
How to Print a List in Python: 5 Different Ways (with code)
April 13, 2023 - With list comprehension, we can ... Have a look at the code below to understand this concept better: lis = [1, 2, 3, 4, 5] [print(i, end=' ') for i in lis] ... In Python, printing a numbered list is an easy process...
🌐
Reddit
reddit.com › r/learnpython › how do i pretty print a 2d array in python?
How do I pretty print a 2D array in Python? : r/learnpython
November 20, 2017 - There is also an end option, which specifies what to add after everything is printed. It defaults to "\n" (newline) which is why consecutive prints are on individual lines. You can override this, print(4,5,6,end="", flush=True). You will also want to specify flush=True to force the print buffer to be flushed (displayed).
Top answer
1 of 2
24

In order to print a numpy.array into a single line, you can convert it to a list with its built-in function numpy.tolist()

Example:

import numpy as np

arr = np.array(((1, 2, 3), (4, 5, 6), (7, 8, 9)))

Simple print of array:

print(arr)
[[1, 2, 3]
 [4, 5, 6]
 [7, 8, 9]]

In comparison with numpy.tolist():

print(array.tolist())
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
2 of 2
8

NumPy provides a few ways to customize the printing, for example np.array2string.

For this answer I assume you have such an array:

>>> import numpy as np
... arr = np.array([[ 0.15555605,  0.51031528,  0.84580176,  0.06722675],
...                 [ 0.60556045,  0.62721023, -0.48979983, -0.04152777],
...                 [-0.78044785,  0.58837543, -0.21146041, -0.13568023],
...                 [ 0.        ,  0.        ,  0.        ,  1.        ]])
  • If you want to display all items you need to make sure that you set threshold to np.inf.
  • In case you want to have , as separator, you can set separator to ','.

However it doesn't have an option to remove the line breaks, just

  • max_line_width which gives the number of characters printed in one line for the innermost dimension. So it works for 1D arrays when you set max_line_width=np.inf but it doesn't work out of the box for ND arrays.

Fortunately it returns a string that can be manipulated, for example by removing all linebreaks:

>>> np.array2string(arr, threshold=np.inf, max_line_width=np.inf, separator=',').replace('\n', '')
'[[ 0.15555605, 0.51031528, 0.84580176, 0.06722675], [ 0.60556045, 0.62721023,-0.48979983,-0.04152777], [-0.78044785, 0.58837543,-0.21146041,-0.13568023], [ 0.        , 0.        , 0.        , 1.        ]]'

Or use a regular expression to remove all whitespaces:

>>> import re
>>> re.sub(r'\s+', '', np.array2string(arr, threshold=np.inf, max_line_width=np.inf, separator=','))
'[[0.15555605,0.51031528,0.84580176,0.06722675],[0.60556045,0.62721023,-0.48979983,-0.04152777],[-0.78044785,0.58837543,-0.21146041,-0.13568023],[0.,0.,0.,1.]]'

Agreed these aren't really "short" and they are also slower than converting to a list with .tolist() and then to a string but it's probably a good alternative especially if you want to customize the printed result without creating a (potentially huge) unnecessary list.