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! ;)
1import re
2s = '\n \t this is a string with a lot of whitespace\t'
3s = re.sub('\s+', '', s)
1' hello world! '.strip()
2'hello world!'
3
4
5' hello world! '.lstrip()
6'hello world! '
7
8' hello world! '.rstrip()
9' hello world!'
1a = " yo! "
2b = a.strip() # this will remove the white spaces that are leading and trailing