Удалить все пробелы из String Python
import re
s = '\n \t this is a string with a lot of whitespace\t'
s = re.sub('\s+', '', s)
Helpful Hippopotamus
import re
s = '\n \t this is a string with a lot of whitespace\t'
s = re.sub('\s+', '', s)
sentence = ' hello apple'
sentence.strip()
>>> 'hello apple'
' hello world! '.strip()
'hello world!'
' hello world! '.lstrip()
'hello world! '
' hello world! '.rstrip()
' hello world!'
>>> " xyz ".rstrip()
' xyz'
' sss d ssd s'.replace(" ", "")
# output: 'sssdssds'
>>> s.strip()
'Hello World From Pankaj \t\n\r\tHi There'