Difference between Newline Character and Carriage Return
Newline (\n) | Carriage return (\r) | |
---|---|---|
Meaning | The Signifies the end of the line of text and the beginning of a new one | HelloWorld beginning HelloWorld of the current line |
Usage | They are Commonly used in the text files and when printing output to the console to create new lines | Less commonly used, typically only necessary in specific text formats for overwriting or modifying existing text |
Syntax | The Represented using escape character sequence \n | The Represented using escape character sequence \r |
Example |
print(“Hello\nWorld”) outputs: Hello World |
print(“Hello\rworld”) outputs: HelloWorld |
difference between newline and carriage return in python
The newline and carriage return are two special characters used to control text’s display and formatting. Although they may appear similar they have distinct functionalities & serve different purposes. This article aims to provide a clear understanding of the difference between newline & carriage return in Python.
- The newline character is represented by “\n” & it is used to create a new line in the string or file.
- The carriage return character represented by “\r” moves the cursor to the beginning of the current line without advancing to the next line.
Contact Us