\r and \n differences in Python

Solved
excelise -  
excelise Posted messages 12 Status Member -
Hello,

In Python, what is the difference between \r and \n?
I'm referring here to two elements that are sometimes included in strings.

Thank you in advance

Configuration: Windows Vista / Internet Explorer 8.0

1 answer

fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
 
\r corresponds to the ASCII character CR.
\n corresponds to the ASCII character LF.

CR will allow you to return to the beginning of the line while LF will allow you to go to the next line.

Best regards,
--

Google is your friend
27
excelise Posted messages 12 Status Member 2
 
Thank you very much, fiddy. What surprises me is that
\n
automatically goes to the next line, right?
For example in
input("your message \n")
0
fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
 
Going to the next line or returning to the line is the same.
0
excelise Posted messages 12 Status Member 2
 
Thank you, fiddy. Yet sometimes we find
\r\n
Strange.
0
fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
 
Yes. Because in fact this is more complicated than I explained to you.
It depends on the OS.
Specifically, to go to the next line under Windows, you need to use \r\n.
Under GNU/Linux, you need to use \n, and under Mac OS, \r.
0
excelise Posted messages 12 Status Member 2
 
Perfect, thank you. My question is resolved.
0