One, remove spaces
strip()
" xyz ".strip() # returns "xyz"" xyz ".lstrip() # returns "xyz "" xyz ".rstrip() # returns " xyz"" x y z ".replace(' ', '') # returns "xyz"
Second, replace replace("space","")
Use replace("\n", "") to replace the preceding string with the following string