how to remove \ n from a string in python

0

I'm trying to exclude control strings from (\n, \t, \u) of strings in Python and I can not do it with either replace or re.sub() . How could I do it?

I've tried, and they have not worked:

p = re.sub('\n', '', p)


p.replace("\n","")
    
asked by anonymous 06.04.2018 / 17:44

1 answer

2

With replace possible, just re-assign the output to the variable.

minha_string = "teste \n teste"
print(minha_string)
print("==============================")

minha_string = minha_string.replace('\n', '')
print(minha_string)

Output:

teste
 teste
==============================
teste  teste
    
06.04.2018 / 17:52