This doesn't work as sep requires several parameters in print to have an effect.

You have many ways.

split and unpacking:

s = 'Hi I am Mike'
print(*s.split(), sep="...")

split and str.join:

s = 'Hi I am Mike'
print('...'.join(s.split()))

str.replace:

s = 'Hi I am Mike'
print(s.replace(' ', '...'))

Output: Hi...I...am...Mike

Answer from mozway on Stack Overflow
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ python-program-to-replace-the-spaces-of-a-string-with-a-specific-character
Python Program to Replace the Spaces of a String with a Specific Character
In Python, spaces in a string can be replaced with specific characters using the replace() method. The replace() method substitutes all occurrences of a specified substring with a new substring.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
July 11, 2025 - The strip() method is used to remove whitespace from the start and end of a string. For removing whitespace from the entire string, replace() can be used, and for more sophisticated patterns, you can use regular expressions via the re module. When using print() with multiple arguments, Python ...
Discussions

python - How to replace whitespaces with underscore? - Stack Overflow
I want to replace whitespace with underscore in a string to create nice URLs. So that for example: ... I am using Python with Django. Can this be solved using regular expressions? ... How can this this be achieved in django template. Is there any way to remove white spaces. More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Replace spaces in string - Code Review Stack Exchange
5 Minimum amount of spaces inserted in a given string, such that it gets composed only of elements from a given list More on codereview.stackexchange.com
๐ŸŒ codereview.stackexchange.com
April 23, 2016
Replace single character in string with space
i have a string str = i am a good boy i want to write a regex that would replace my single letter character with space. is there anyโ€ฆ More on reddit.com
๐ŸŒ r/learnpython
7
0
September 8, 2016
substitution - Substitute multiple whitespace with single whitespace in Python - Stack Overflow
I have this string: mystring = 'Here is some text I wrote ' How can I substitute the double, triple (...) whitespace chracters with a single space, so that I get: mystring = 'Here is ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-replace-multiple-whitespaces-in-a-python-string-417565
How to replace multiple whitespaces in a Python string | LabEx
One of the most elegant and efficient ways to replace multiple whitespaces in Python is using a combination of the split() and join() methods. This approach is both simple and powerful. split(): When called without arguments, this method splits ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to replace spaces in a python string with a specific character
5 Best Ways to Replace Spaces in a Python String with a Specific Character - Be on the Right Side of Change
February 26, 2024 - This method employs the string replace() function, which is built into Pythonโ€™s standard library. Itโ€™s specifically designed to replace occurrences of a substring within a string with another specified substring. This method is straightforward and easy to use for such a common task. ... This code snippet takes a string text and uses the replace() method to substitute all spaces with underscores, assigning the result to new_text.
Find elsewhere
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ re โ€บ python-re-exercise-23.php
Python: Replace whitespaces with an underscore and vice versa - w3resource
Write a Python program to search for both spaces and underscores in a string and swap them using regex substitution.
๐ŸŒ
Python Guides
pythonguides.com โ€บ replace-multiple-spaces-with-a-single-space-in-python
Replace Multiple Spaces with a Single Space in Python
October 28, 2025 - I often use it when cleaning up imported text data or preparing strings for NLP (Natural Language Processing) tasks. If you want more control or need to handle complex spacing patterns, Pythonโ€™s re module is your best friend. The re.sub() function lets you replace all occurrences of a pattern, ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ replace single character in string with space
r/learnpython on Reddit: Replace single character in string with space
September 8, 2016 - where the r'your-regex-here' lets you avoid escaping backslashes, and the \s actually lets you replace the space behind a single character word so that you don't have two spaces between words after the replacement.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ replace-underscores-with-spaces-in-python
Replace Underscores with Spaces in Python
July 1, 2022 - Regardless of where you see this, you may need to convert these underscores to spaces in your code. We'll see how to do that here. The simplest way to achieve this is to use the string's replace(substr, new_str) method, which takes a substring as an argument, as well as the new string to replace ...
๐ŸŒ
Medium
medium.com โ€บ @parvez1487 โ€บ python-replace-multiple-spaces-with-one-pythonpip-com-21d8fed04b55
Python Replace Multiple Spaces with One โ€” pythonpip.com | by Parvez Alam | Medium
January 13, 2024 - This is an example with consecutive spaces. The re module in Python allows us to find and replace multiple spaces efficiently.
๐ŸŒ
Python Guides
pythonguides.com โ€บ replace-whitespaces-with-underscore-in-python
Python Replace Whitespaces With Underscore
August 25, 2025 - Notice how this method automatically removes extra spaces at the beginning, middle, and end of the string. That makes it a great choice for cleaning up inconsistent data. If youโ€™re just starting with Python, you might want to see how this can be done manually with a loop. Although I donโ€™t usually use this in production, itโ€™s a good way to understand how string manipulation works. ... # Example: Replace spaces with underscores using a for loop text = "Chicago Population Growth Report" result = "" for char in text: if char == " ": result += "_" else: result += char print("Original:", text) print("Modified:", result)
๐ŸŒ
Tutor Python
tutorpython.com โ€บ python-replace-space-with-underscore
Python Replace Space with Underscore - Tutor Python
October 19, 2023 - This aspect bears significant importance in such situations. The replace() method is a built-in function in Python that allows us to replace occurrences of a specified substring with another substring.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ methods to remove spaces from text
r/learnpython on Reddit: methods to remove spaces from text
December 20, 2023 -

Hi everyone, I recently took the Fullstack Python Developer course and am now taking my first steps on this path.
Can you tell me what other methods of removing spaces from text you know and in which case, each of them is better to use?
So far I know 4 of them:

  1. replace method -> text_wo_spaces = text.replace(" ","")

  2. join and split methods -> text_wo_spaces = ' '.join(text.split())

  3. list generator + join -> text_wo_spaces = ' '.join([char for char in text if char != ' '])

  4. filter + join methods -> text_wo_spaces = ' '.join(filter(lambda char : != ' ', text))

๐ŸŒ
CodeFatherTech
codefather.tech โ€บ home โ€บ blog โ€บ how do you remove spaces from a python string?
How Do You Remove Spaces From a Python String? - CodeFatherTech
June 27, 2025 - There are multiple ways to remove spaces from a Python string. The simplest approach is to use the string replace() method. If the spaces to remove are just at the beginning and at the end of the string the strip() method also works fine.