1string = "Hello, world! Some more text here..." # Just a string
2string.replace(" ", "") # Replaces all instances of " " (spaces)with "" (nothing)
3
4# string is now "Hello,World!Somemoretexthere..."
5# I hope I helped you! ;)
1s = ' Hello World From Pankaj \t\n\r\t Hi There '
2
3>>> s.replace(" ", "")
4'HelloWorldFromPankaj\t\n\r\tHiThere'
1>>> import re
2>>> re.sub(' +', ' ', 'The quick brown fox')
3'The quick brown fox'
1#If you want to remove LEADING and ENDING spaces, use str.strip():
2
3sentence = ' hello apple'
4sentence.strip()
5>>> 'hello apple'