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 the above code example, we split the sentence string into words using split() with "Is" as the delimiter. Then, we use ' '.join(words) to join the words back together with a space between them, creating the modified_sentence with spaces. We can also add spaces between words by using the ‘+’ operator to concatenate them with a space in between. sentence1 = “Add” sentence2 = “Spaces” sentence3 = “Python” print(sentence1 + “ “ + sentence2 + “ “ + sentence3) # Output: “Add Spaces Python”
🌐
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() ...
🌐
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}")

🌐
Real Python
realpython.com › ref › glossary › whitespace
whitespace | Python Glossary – Real Python
Space ( ) – The most common whitespace character ... >>> " hello world ".strip() 'hello world' >>> " hello world ".split() ['hello', 'world'] >>> " \t\n".isspace() True · Here’s a quick example showing how Python uses whitespace for indentation ...
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › how-to-check-for-spaces-in-python-string
How to check for spaces in Python string?
August 25, 2023 - Regular expressions provide powerful pattern matching for detecting various types of whitespace characters including spaces, tabs, and newlines. import re text = "Welcome to Tutorialspoint" # Check for any whitespace using regex if re.search(r'\s', text): print("String contains whitespace") else: print("String does not contain whitespace") # Find all whitespace positions whitespace_positions = [m.start() for m in re.finditer(r'\s', text)] print(f"Whitespace found at positions: {whitespace_positions}")
🌐
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.
🌐
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 ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
July 11, 2025 - Remove all spaces using regex: HelloWorldFromDigitalOceanHiThere Remove leading spaces using regex: Hello World From DigitalOcean Hi There Remove trailing spaces using regex: Hello World From DigitalOcean Hi There Remove leading and trailing spaces using regex: Hello World From DigitalOcean Hi There · When removing whitespace from strings, especially in performance-critical applications or when processing large volumes of text, the efficiency of the method you choose matters. This section compares the performance of the primary methods discussed and provides guidance on when to use each one. We will use Python’s built-in timeit module to benchmark the replace(), join()/split(), translate(), and re.sub() methods.
🌐
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 ...
🌐
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.
🌐
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 - We define the string 's'. The 'in' operator checks if there is a space in 's'.
🌐
Delft Stack
delftstack.com › home › howto › python › python pad string with spaces
How to Pad String With Spaces in Python | Delft Stack
February 2, 2024 - In this code, we utilized Python’s string formatting technique. We define a format string "s", which acts as a template for the string’s formatting. The % signifies a placeholder for the string, and 15 sets the desired total width. By using the % operator, we insert the string "I am legend" into the placeholder. ... The output of this code will be I am legend with enough spaces added to its left to make it a total of 15 characters wide.
🌐
Codecademy
codecademy.com › docs › python › strings › .isspace()
Python | Strings | .isspace() | Codecademy
October 3, 2023 - The .isspace() string method takes in a string and returns True if the entire string is composed of whitespace characters, otherwise False. Whitespace characters include: Space (‘ ‘) Horizontal tab (‘\t’) Newline (‘\n’) Vertical ...
🌐
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