python replace n in string code example
Example 1: python replace newline
without_line_breaks = a_string.replace("\n", " ")
Example 2: python replace string
string.replace(old, new, count)
Example 3: python replace \n with something else
>>> import re
>>> re.sub('\r?\n', ' $ ', 'a\r\nb\r\nc')
'a $ b $ c'
>>> re.sub('\r?\n', ' $ ', 'a\nb\nc')
'a $ b $ c'