You can do this with str.ljust(width[, fillchar]):

Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is a space). The original string is returned if width is less than len(s).

>>> 'hi'.ljust(10)
'hi        '
Answer from Felix Kling on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_isspace.asp
Python String isspace() Method
Python HOME Python Intro Python Get Started Python Syntax ... Python Variables Variable Names Assign Multiple Values Output Variables Global Variables Variable Exercises Code Challenge Python Data Types ... Python Strings Slicing Strings Modify Strings Concatenate Strings Format Strings Escape Characters String Methods String Exercises Code Challenge Python Booleans
Discussions

STRING METHOD FOR SPACES
Use the in operator. if " " in email: ... More on reddit.com
๐ŸŒ r/learnpython
6
1
August 16, 2023
python - Efficient way to add spaces between characters in a string - Stack Overflow
Say I have a string s = 'BINGO'; I want to iterate over the string to produce 'B I N G O'. This is what I did: result = '' for ch in s: result = result + ch + ' ' print(result[:-1]) # to ri... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Add a space in string - Stack Overflow
How can I add a blank space in Python? Ex. print "How many times did " + name + "go here?"; will print: How many times didnamego here?" How can I add that space in? More on stackoverflow.com
๐ŸŒ stackoverflow.com
April 18, 2011
\n giving me an extra space on new line?
Yeah learn f-strings. For this particular problem though I'd just use two print statements for readability. Python print has an optional separator keyword argument (sep = ' ') but it will use it on all values separated by commas. The default is sep = ' ', not sep = ''. print(1, 2, 3) -> 1 2 3 print(1, 2, 3, sep = '') -> 123 print(1, 2, 3, sep = '*') -> 1*2*3 Edit: It's always worth checking out the documentation, it's a good habit. https://docs.python.org/3/library/functions.html#print More on reddit.com
๐ŸŒ r/learnpython
29
53
April 26, 2023
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ fill-a-python-string-with-spaces
Fill a Python String with Spaces - GeeksforGeeks
July 23, 2025 - Note that in the case of space around the string if N is odd then the extra space is added to the right of the string. Input: string = "GeeksforGeeks" N = 2 Output: Right: "GeeksforGeeks " Left: " GeeksforGeeks" Around: " GeeksforGeeks " Input: string = "Geek" N = 5 Output: Right: "Geek " Left: " Geek" Around: " Geek " For more effective handling of sophisticated string formatting, the Python string format() method has been developed.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ string method for spaces
r/learnpython on Reddit: STRING METHOD FOR SPACES
August 16, 2023 -

Is there any string method that checks for spaces? I know isspace() checks for them but it only gives a true if the string only includes white spaces. I'm looking for one that will prince a false if there is any spaces. I'm using these for a project that splices emails so isalpha() wont work cos of that @ and numeric symbols

here is the code

print("Your email may not contain any spaces.")

email = input("Enter your email: ")

index = email.index("@") # this method will return a number

print(index)

username = email[:index]

domain = email[index:]

print(f"your username is {username} and domain is {domain}")

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ string-whitespace-in-python
string.whitespace in Python - GeeksforGeeks
July 11, 2025 - In Python, string.whitespace is a string containing all the characters that are considered whitespace. Whitespace characters include spaces, tabs, newlines and other characters that create space in text.
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ glossary โ€บ whitespace
whitespace | Python Glossary โ€“ Real Python
A character that represents blank space in text, used in Python for indentation and string processing.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-add-a-space-between-words-in-a-string-in-python
How to add a space between words in a string in Python
print: We can add spaces between words by listing them as commas separated in the print() statement. We add spaces between words using the join() method, which accepts a list and returns a string. ... We can use + operator to concatenate two strings.
Find elsewhere
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ string โ€บ isspace
Python String isspace()
Python String expandtabs() Characters that are used for spacing are called whitespace characters. For example: tabs, spaces, newline, etc. The syntax of isspace() is: string.isspace() isspace() method doesn't take any parameters. isspace() method returns: True if all characters in the string ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-check-for-spaces-in-python-string
How to check for spaces in Python string?
August 25, 2023 - The in operator checks if a space character exists anywhere in the string.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-string-isspace-method
Python String isspace() Method - GeeksforGeeks
January 2, 2025 - isspace() method in Python is used to check if all characters in a string are whitespace characters. This includes spaces (' '), tabs (\t), newlines (\n), and other Unicode-defined whitespace characters.
๐ŸŒ
Toppr
toppr.com โ€บ guides โ€บ python-guide โ€บ references โ€บ methods-and-functions โ€บ methods โ€บ string โ€บ isspace โ€บ python-string-isspace
Python isspace() function | Why do we use Python String isspace()? |
August 26, 2021 - The Python isspace() String function examines a string for whitespace characters and returns True only if the string contains all spacing characters; else it returns False. Python isspace() is a built-in method that returns True if all of the characters in the string are spacing characters ...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
Master Python string manipulation by learning how to remove whitespace and manage spaces with techniques like strip(), replace(), and regex for cleaner data.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-check-for-spaces-in-string
Python - Check for spaces in string - GeeksforGeeks
July 12, 2025 - We define the string 's'. The 'in' operator checks if there is a space in 's'.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ pad string with spaces in python
Pad String with Spaces in Python - Spark By {Examples}
May 21, 2024 - How to pad the string with spaces in Python? Adding some characters to the string is known as Padding or filling and is useful when you wanted to make a
Top answer
1 of 4
12
print "How many times did " + name + " go here?"

or

print "How many times did", name, "go here?"

or

print "How many times did %s go here?" % name

The preferred form in this simple case is the second one. The first uses concatenation (which is useful if you want more or less than one space between parts), the second uses the comma operator, which in the context of print joins the strings with a space, and the third uses string formatting (the old style), which should look familiar if you come from C, Perl, PHP, etc. The third is the most powerful form, but in this simple cases the use of format strings is unnecessary.

Note that in Python, lines do not need to be (and should not be) ended by semicolons. You can also use some of the string justification methods to add several spaces on either or both sides of the string.

2 of 4
6

@yookd: Welcome to SO. This is not a real answer, just some suggestions for asking better questions.

Please check what you have typed before posting. Your print statement does not print what you say it does. In fact it doesn't print anything, because it has a syntax error.

>>> name = "Foo"
>>> print "How many times did " + name "go here?";
  File "<stdin>", line 1
    print "How many times did " + name "go here?";
                                                ^
SyntaxError: invalid syntax

You are missing a + after name:

>>> print "How many times did " + name + "go here?";
How many times did Foogo here?

And even after fixing the syntax error it doesn't do what you said it does. What it does do is demonstrate one of the ways of getting a space (including it in the constant text).

Hint: To save checking, enter your code at the Python interactive prompt and then copy/paste the code and the results straight into your question, just as I did in this "answer".

๐ŸŒ
Quora
quora.com โ€บ How-do-I-print-with-spaces-in-Python
How to print with spaces 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.