What is difference in a string between \r\n
, \r
and \n
? How is a string affected by each?
I have to replace the occurrences of \r\n
and \r
with \n
, but I cannot get how are they different in a string...
I know that \r
is like hitting enter and \n
is for a new line.
\n means new line. It means that the cursor must go to the next line. \r means carriage return. It means that the cursor should go back to the beginning of the line.
historically a \n was used to move the carriage down, while the \r was used to move the carriage back to the left side of the page.
In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return.
Just (invisible) entries in a string. \r moves cursor to the beginning of the line. \n goes one line down.
\r
= CR (Carriage Return) → Used as a new line character in Mac OS before X\n
= LF (Line Feed) → Used as a new line character in Unix/Mac OS X\r\n
= CR + LF → Used as a new line character in WindowsIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With