Answers for "python remove all whitespace but spaces"

10

how to remove all spaces from a string in python

string = "Hello, world! Some more text here..." # Just a string
string.replace(" ", "") # Replaces all instances of " " (spaces)with "" (nothing)

# string is now "Hello,World!Somemoretexthere..."
# I hope I helped you! ;)
Posted by: Guest on March-11-2021
0

python remove white space

>>> '     hello world!    '.strip() #remove both
'hello world!'

>>> '     hello world!'.lstrip() #remove leading whitespace
'hello world!'
Posted by: Guest on November-23-2021

Code answers related to "python remove all whitespace but spaces"

Python Answers by Framework

Browse Popular Code Answers by Language