I\'m trying to remove all newline characters from a string. I\'ve read up on how to do it, but it seems that I for some reason am unable to do so. Here is step by step what
strip() returns the string with leading and trailing whitespaces(by default) removed.
So it would turn " Hello World " to "Hello World", but it won't remove the \n character as it is present in between the string.
" Hello World "
"Hello World"
Try replace().
str = "Hello \n World" str2 = str.replace('\n', '') print str2