Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between \n and \r\n?

They both mean "new line" but when is one used over the other?

like image 595
Emanuil Rusev Avatar asked Sep 29 '10 13:09

Emanuil Rusev


People also ask

Is \n and \r same?

The /r stands for return or carriage return which owes it's history to the typewriter. A carriage return moved your carriage all the way to the right so you were typing at the start of the line. The /n stands for new line, again, from typewriter days you moved down to a new line.

What does \r and \n mean?

\r and \n are digital representations of the way you would advance to the next line on a typewriter. \r is a carriage return and \n is a newline (also known as a linefeed). On a typewriter, to go to the start of the new line, you would return the carriage to the leftmost position and then feed the paper up a line.

What is difference between \r and \n in Python?

"\n" is the class Unix/linux style for new line. "\r\n" is the default Windows style for line separator. "\r" is classic Mac style for line separator.


2 Answers

\r\n is a Windows Style

\n is a POSIX Style

\r is a old pre-OS X Macs Style, Modern Mac's using POSIX Style.


\r is a carriage return and \n is a line feed, in old computers where it not have monitor, have only printer to get out programs result to user, if you want get printing from staring of new line from left, you must get \n for Line Feed, and \r for get Carriage return to the most left position, this is from old computers syntax saved to this time on Windows platform.

like image 167
Svisstack Avatar answered Sep 30 '22 06:09

Svisstack


\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.

Unix programs usually only needs a new line (\n).

Windows programs usually need both.

like image 45
Philippe Carriere Avatar answered Sep 30 '22 05:09

Philippe Carriere