This print("{0:10d}".format(5)) will print 5 after 9 blanks. For more reference on formatting in python refer this.

Answer from Siddharth on Stack Overflow
🌐
Quora
quora.com › How-do-I-print-with-spaces-in-Python
How to print with spaces in Python - Quora
Python (programming langu... ... Printing with spaces in Python can mean several things: inserting spaces between items, formatting a string with fixed spacing, padding values to widths, or joining items with a specific separator.
Discussions

How to print spaces in Python? - Stack Overflow
In C++, \n is used, but what do I use in Python? I don't want to have to use: print (" "). This doesn't seem very elegant. Any help will be greatly appreciated! More on stackoverflow.com
🌐 stackoverflow.com
python 3.x - Print numbers with spaces in Python3 - Stack Overflow
I have a list of numbers that I want to print as follows: 1 1 3 11 58 451 4 461 49 957 598 102 7 437 910 94 944 685 Curre... More on stackoverflow.com
🌐 stackoverflow.com
string - Python - Printing numbers with spacing format - Stack Overflow
Let's say I have an array of numbers where list = [(4, 3, 7, 23),(17, 4021, 4, 92)] and I want to print the numbers out in such a way so that the output looks somewhat like this: [ 4 | 3 | ... More on stackoverflow.com
🌐 stackoverflow.com
August 25, 2016
How do I add space between two variables after a print in Python - Stack Overflow
To do this is the newer, more pythonic ... with a letter to denote the kind of value we're using. Here I use underscores instead of spaces to show how many there are. The modulo before the last values just tells python to insert the following values in, in the order we provided. print ('%i____%s' % (count, conv)) ### provides an output of: 1____2.54 · I used %i for count because it is a whole number, and %s for ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
IncludeHelp
includehelp.com › python › how-to-print-spaces-in-python.aspx
How to print spaces in Python?
April 8, 2023 - x = 10 y = 20 space = ' ' ''' 2 spaces would be here 1 space after first parameter, 1 space by using space variable 1 space after second parameter ''' print("Hello",space,"world") ''' 7 spaces would be here 1 space after first parameter, 5 space by using space*5 1 space after second parameter ''' print("Hello",space*5,"world") ''' 12 spaces would be here 1 space after first parameter, 10 space by using space*10 1 space after second parameter ''' print("Hello",space*10,"world") # for better better understanding # assign space by any other character # Here, I am assigning '#' space = '#' print("
🌐
Finxter
blog.finxter.com › home › learn python blog › how to print spaces in python
How to Print Spaces in Python - Be on the Right Side of Change
September 21, 2022 - employee = 'James,Smith,Teacher,jsmith@acme.org,Toronto,Canada' spaced = employee.replace(',', ' '*5) print(spaced) The above code declares a comma-delimited row containing an employee’s data. This data saves to employee. Next, replace() is appended to employee and two (2) arguments are passed: The string to replace (','). The string to replace the above with. Which, in this case, is the space (' ') character multiplied by the number of occurrences (' '*5). The results save to spaced and are output to the terminal. This example uses Python’s f-string and chr() to print multiple spaces between two variables.
🌐
Quora
quora.com › How-do-I-output-a-list-of-numbers-as-numbers-separated-by-space-in-Python
How to output a list of numbers as numbers separated by space in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
Find elsewhere
🌐
Quora
quora.com › How-do-I-print-numbers-in-Python-without-space-in-one-line
How to print numbers in Python without space in one line - Quora
Answer (1 of 4): Print(number,end=””) it will print the nunber without space ,by default end use \n which is next line so by overriding the end function using end=”” it will print without space.
🌐
Replit
replit.com › home › discover › how to print a space in python
How to print a space in Python | Replit
We pass the spaces variable and the name "Alice" to fill the template, creating a neatly formatted string with a specific gap. This approach is great for building structured output where the spacing might need to be calculated dynamically before being inserted. While basic operators are useful, Python also offers specialized escape sequences and string methods that give you more precise control over spacing and text alignment. ... print("Line one\nLine two") # Newline print("Column one\tColumn two") # Tab space print("No break space: a\u00A0b") # Non-breaking space
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-print-spaces-in-python3
How to print spaces in Python3? - GeeksforGeeks
August 1, 2020 - # Python program to print spaces x = 1 y = 2 # use of "," symbol print("x:",x) print("y:",y) print(x,"+",y,"=",x+y) ... Example 3: Print multiple spaces between two values.
🌐
Quora
quora.com › How-can-I-print-a-list-of-integers-separated-by-space-in-one-line-of-code-in-Python
How to print a list of integers separated by space in one line of code in Python - Quora
Answer (1 of 6): N̲e̲e̲d̲ ̲t̲o̲ ̲p̲r̲i̲nt̲ ̲a̲ ̲l̲i̲s̲t̲ ̲o̲f̲ ̲n̲u̲m̲be̲rs̲ s̲e̲p̲a̲r̲a̲t̲e̲d̲ ̲b̲y̲ s̲p̲a̲c̲e̲s̲ ̲w̲i̲t̲h̲o̲u̲t ̲c̲o̲m̲m̲a̲s̲ ̲o̲r̲ ̲b̲r̲a̲c̲k̲e̲t̲s̲ ̲?̲ ̲H̲e̲r̲e̲’̲s̲ ̲h̲o̲w̲ ...
Top answer
1 of 10
141

Here is bad but simple solution if you don't want to mess with locale:

'{:,}'.format(1234567890.001).replace(',', ' ')
2 of 10
38

Answer of @user136036 is quite good, but unfortunately it does not take into account reality of Python bugs. Full answer could be following:

Variant A

If locale of your platform is working right, then just use locale:

import locale
locale.setlocale(locale.LC_ALL, '')
print("{:,d}".format(7123001))

Result is dependent on your locale and Python implementation working right.

But what if Python formatting according to locale is broken, e.g. Python 3.5 on Linux?

Variant B

If Python does not respect grouping=True parameter, you can use locale and a workaround (use monetary format):

locale.setlocale(locale.LC_ALL, '')
locale._override_localeconv = {'mon_thousands_sep': '.'}
print(locale.format('%.2f', 12345.678, grouping=True, monetary=True))

Above gives 12.345,68 on my platform. Setting monetary to False or omitting it - Python does not group thousands. Specifying locale._override_localeconv = {'thousands_sep': '.'} do nothing.

Variant C

If you don't have time to check what is working OK and what is broken with Python on your platform, you can just use regular string replace function (if you want to swap commas and dot to dots and comma):

print("{:,.2f}".format(7123001.345).replace(",", "X").replace(".", ",").replace("X", "."))

Replacing comma for space is trivial (point is assumed decimal separator):

print("{:,.2f}".format(7123001.345).replace(",", " ")

🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-62.php
Python: Print a list of space-separated elements - w3resource
June 28, 2025 - # Define a list 'num' containing integers num = [1, 2, 3, 4, 5] # Use the '*' operator in a print statement to unpack the elements of the list 'num' as separate arguments # This will print each element of the list separated by spaces print(*num) ...
🌐
Team Treehouse
teamtreehouse.com › community › format-numbers-in-python
Format numbers in Python (Example) | Treehouse Community
September 9, 2016 - It will be commas though, not spaces. num = 132489893342325 print("{0:,}".format(num)) # OUTPUT 132,489,893,342,325 ... Since that would be a string output he could then use str.replace(",", " ") to achieve spaces. Posting to the forum is only ...
Top answer
1 of 4
156

You can apply the list as separate arguments:

print(*L)

and let print() take care of converting each element to a string. You can, as always, control the separator by setting the sep keyword argument:

>>> L = [1, 2, 3, 4, 5]
>>> print(*L)
1 2 3 4 5
>>> print(*L, sep=', ')
1, 2, 3, 4, 5
>>> print(*L, sep=' -> ')
1 -> 2 -> 3 -> 4 -> 5

Unless you need the joined string for something else, this is the easiest method. Otherwise, use str.join():

joined_string = ' '.join([str(v) for v in L])
print(joined_string)
# do other things with joined_string

Note that this requires manual conversion to strings for any non-string values in L!

2 of 4
10

Although the accepted answer is absolutely clear, I just wanted to check efficiency in terms of time.

The best way is to print joined string of numbers converted to strings.

print(" ".join(list(map(str,l))))

Note that I used map instead of loop. I wrote a little code of all 4 different ways to compare time:

import time as t

a, b = 10, 210000
l = list(range(a, b))
tic = t.time()
for i in l:
    print(i, end=" ")

print()
tac = t.time()
t1 = (tac - tic) * 1000
print(*l)
toe = t.time()
t2 = (toe - tac) * 1000
print(" ".join([str(i) for i in l]))
joe = t.time()
t3 = (joe - toe) * 1000
print(" ".join(list(map(str, l))))
toy = t.time()
t4 = (toy - joe) * 1000
print("Time",t1,t2,t3,t4)

Result:

Time 74344.76 71790.83 196.99 153.99

The output was quite surprising to me. Huge difference of time in cases of 'loop method' and 'joined-string method'.

Conclusion: Do not use loops for printing list if size is too large( in order of 10**5 or more).