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
Sign In โ˜… +1 Get Certified Upgrade Academy Spaces Practice Get Certified Upgrade Academy Spaces Practice ... HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP W3.CSS C C++ C# HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ...
Discussions

STRING METHOD FOR SPACES
Use the in operator. if " " in email: ... More on reddit.com
๐ŸŒ r/learnpython
6
1
August 16, 2023
How to print spaces in Python? - Stack Overflow
I prefer to use string format replacement ( %s ) instead. I have typed out a long explanation / answer below. 2019-01-25T20:25:53.537Z+00:00 ... To be clear, parentheses may not be needed in Python 2, but they are most definitely needed in Python 3. 2021-06-24T20:01:19.733Z+00:00 ... Save this answer. ... Show activity on this post. If you need to separate certain elements with spaces ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
\n giving me an extra space on new line?
Personally, I'd use an f-string. print(f"{3+5}\n{2**3} {17-9} {32/4}") since using separate arguments adds a space. I think you could also add a "\b" to get rid of the space but you'd have to do something like f"\b{2**3}" anyway since adding it as a separate argument will add another space after the one you delete! More on reddit.com
๐ŸŒ r/learnpython
29
53
April 26, 2023
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ add-spaces-python
How to add spaces in Python - Flexiple
March 26, 2024 - In this blog - โ€œHow to add spaces in Pythonโ€, we will explore different methods in Python to easily add spaces within strings, covering techniques to add spaces between words and characters, as well as at the beginning and end of a string.
๐ŸŒ
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.
๐ŸŒ
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 ... 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() ...
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-check-for-spaces-in-python-string
How to check for spaces in Python string?
August 25, 2023 - Checking for spaces (whitespaces) in Python strings is a common task when processing text data. Python provides several built-in methods to detect spaces in strings, each suitable for different scenarios.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
July 11, 2025 - Master Python string manipulation by learning how to remove whitespace and manage spaces with techniques like strip(), replace(), and regex for cleaner data.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ string โ€บ isspace
Python String isspace()
The isspace() method returns True if there are only whitespace characters in the string. If not, it return False.
๐ŸŒ
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 (space, ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-string-isspace-method
Python String isspace() Method - GeeksforGeeks
January 2, 2025 - The string " " contains only whitespace characters (spaces). The isspace() method returns True since all characters in the string are whitespace. ... The isspace() method does not take any parameters. Returns True if all characters in the string are whitespace. Returns False if the string contains one or more non-whitespace characters or is empty. Let's see what happens when the string contains non-whitespace characters: ... The string contains non-whitespace characters ("Python ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-print-with-spaces-in-Python
How to print with spaces in Python - Quora
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-check-for-spaces-in-string
Python - Check for spaces in string - GeeksforGeeks
July 12, 2025 - Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.