Graphical difference between carriage return and line feed

1. Definition

Chinese English abbreviation HEX Character ASCII
carriage return Carriage return CR 0x0D \r 13
new line Line feed LF 0x0A \n 10

2. Diagram

Win11
Experiment by Pycharm with Python 3.9

    print('---')
    print('Hello World')
    print('---')
    # '\r'
    print('Hello' + '\r' + 'World')
    print('---')
    # '\n'
    print('Hello' + '\n' + 'World')
    print('---')
    # '\r\n'
    print('Hello' + '\r\n' + 'World')
    print('---')

Pycharm output as following

insert image description here

3 Discussion

Enter (\r) to output the Hello Word that should have been output as World.
Line feed (\n) will output the Hello Word that should have been output as the first line Hello and the second line World.
Carriage return and line feed (\r\n) will output the Hello Word that should have been output as the first line Hello, and the second line World.

4 Conclusion

In the experiment of Pycharm with Python 3.9 under the Win11 system, line feed (\n) and carriage return line feed (\r\n) have the same operation results on Hello Word, both of which output the first line Hello and the second line World.

Guess you like

Origin blog.csdn.net/weixin_44392735/article/details/127790380