You can also do what you want with a regular expression. It may be a little exaggerated for the example you have, but it’s always good to know more ways to get to the end result.
All you need to do is search with the regular expression \s
, searching for any white space, i.e., space, enter, tab, and then replace each of these found characters with an empty string:
import re
frase = "O rato roeu a roupa\n Do rei de Roma"
nova_frase = re.sub(r"\s", "", frase) # procura por \s e substitui por ""
print(nova_frase) # 'OratoroeuaroupaDoreideRoma'
Check it out at Ideone
can use . replace(' ',''), this will take out all spaces
– Elton Nunes
Welcome home, this would help you? There is a way to print everything without line break?
– Luiz Augusto