print, by default, prints a space between each argument it prints: >>> print('x', 'y') x y The solution is to use string formatting: print("{} to the power of {} is approximately {}.".format(x, y, round(result))) Answer from MRAB on discuss.python.org
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-spaces-from-a-string
Remove spaces from a string in Python - GeeksforGeeks
Sometimes, we only need to remove spaces from the start and end of a string while leaving the inner spaces untouched. In such cases, strip() method is ideal. ... Explanation: s.strip() removes spaces from the start and end of s.
Published   July 11, 2025
🌐
Reddit
reddit.com › r/python › how do i remove spaces in a print
r/Python on Reddit: How do i remove spaces in a print
June 4, 2020 -

Im just starting out and for a assignment i need to print this line: Print (variable_a, “filler text”) But there can’t be a space between the two. How do i remove this space?

Discussions

python - How to print variables without spaces between values - Stack Overflow
I would like to know how to remove additional spaces when I print something. Like when I do: print 'Value is "', value, '"' The output will be: Value is " 42 " But I want: Value is "42" Is ther... More on stackoverflow.com
🌐 stackoverflow.com
How do I remove space at the end of an output in python? - Stack Overflow
If anyone could guide me on how to remove the space it would be appreciated. ... Please, please, please copy (Ctrl-C) and paste (Ctrl-V) your code and output into your question. More on stackoverflow.com
🌐 stackoverflow.com
How to Remove Spaces From a String in Python (Complete 2026 Guide)
Need to remove spaces in Python? Get one-line solutions, edge-case handling, and when to use each method. More on accuweb.cloud
🌐 accuweb.cloud
1
December 1, 2023
pycharm - How to remove space from print statement in Python? - Stack Overflow
I'm printing a simple line program in Python. But when I add a period after a comma in the print statement, I keep seeing a space in between the end of the result and the period. How can I remove t... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python.org
discuss.python.org › python help
How to remove extra space - Python Help - Discussions on Python.org
September 19, 2022 - Why there is extra spaces (marked ... number: “)) result = x**y print(x,“to the power of”,y,“is approximately”,(round(result)),”.”) print(“To be exact it is”,(round(result, 2)),”.”)...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
July 11, 2025 - let me explain you with an simple example s= (" PYTHON “) #so here i am using both and leading and trailing spaces output= s.strip(” “) # in between double quotes i am using space as i have used space before and after PYTHON print(output) # you will get output as “PYTHON” … another example while using idle --------------------------------------- >>> s= (” python ") >>> s.strip() ‘python’ >>> see both the trailing and leading spaces have been removed
🌐
AskPython
askpython.com › python › string › python-remove-spaces-from-string
Python Remove Spaces from String - AskPython
February 16, 2023 - Then we need to use the join() method to concatenate them. ... def remove(string_input): return "".join(string_input.split()) # Driver Program string_input= ' S a f a ' print(remove(string_input)) ... In the above example, the translate() function removes all of the white-spaces from the string and results in a compact string as output.
Find elsewhere
🌐
Accuweb
accuweb.cloud › home › how to remove spaces from a string in python (complete 2026 guide)
How to Remove Spaces From a String in Python (Complete 2026 Guide)
December 1, 2023 - s = " This s tring needs to remove whitespace " result = "" for ch in s: if not ch.isspace(): result += ch print(result) Output: ThisstringneedstoremovewhitespaceCopy ... Not recommended for performance-critical systems. Regex is the most powerful and flexible method. import re import itertools s = " This String Ne eds to remo ve white space " clean = re.sub(r"\s+", "", s) print(clean) Output: ThisStringNeedstoremovewhitespaceCopy
🌐
FavTutor
favtutor.com › blogs › remove-space-from-string-python
Remove Spaces from String in Python | FavTutor
January 6, 2022 - ... Using this method, only the trailing spaces can be removed in a string. ... The string strip() method can be used to eliminate spaces from both the beginning and end of a string.
🌐
CloudSigma
blog.cloudsigma.com › removing-spaces-in-python
Removing Spaces in Python — CloudSigma
May 16, 2023 - If you want to remove just the leading or tailing spaces, then use lstrip() or rstrip() respectively:
🌐
GeeksforGeeks
geeksforgeeks.org › python-remove-unwanted-spaces-from-string
Python | Remove unwanted spaces from string - GeeksforGeeks
April 23, 2023 - Method #1: Using re.sub() This problem can be performed using the regex in which we can restrict the separation between the words to be just a single space using the appropriate regex string.
🌐
Python.org
discuss.python.org › python help
How to remove extra space from output list tuple? - Python Help - Discussions on Python.org
May 5, 2022 - Hi, I have this input [python]P (0, 2,+1) (2, 0, -1) (0, 4,+1) (4, 0, -1)[/python] and I would like to have it printed out this way [python][(0, 2, 1), (2, 0, -1), (0, 4, 1), (4, 0, -1)][/python]. However, due to the ex…
🌐
Delft Stack
delftstack.com › home › howto › python › python print without space
How to Print Values Without Spaces in Between in Python | Delft Stack
February 2, 2024 - In this case, by setting it to an empty string, we achieve the desired format without any extra spaces or separators. Python’s string.Template can be used to interpolate values into a template string.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-strip-trailing-whitespace-in-python
Trim a String in Python – How to Strip Trailing Whitespace
March 3, 2023 - Python has the rstrip() method you can use to do just that: fave_phrase = " Hello World " trimmed_fave_phrase = fave_phrase.rstrip() print(trimmed_fave_phrase) # output Hello World · In the example above, the leading space at the beginning ...
🌐
Codingem
codingem.com › home › python how to print without spaces (examples)
Python How to Print Without Spaces (Examples) - codingem.com
December 5, 2022 - To print without a space in Python, you can set the sep parameter to specify a separator between the values you are printing.