为什么在使用Python3 print()输出包含'\r'的字符串时会得到不同的结果?

2024-09-27 07:34:01 发布

您现在位置:Python中文网/ 问答频道 /正文

环境是python3.6和win10x64。 我想用print()输出字符串'123456\rabc',正确的结果应该是'abc456',但是我得到了不同的答案。你知道吗

<强>1。IPython:

    Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)]
    Type "copyright", "credits" or "license" for more information.

    IPython 5.3.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

    In [1]: print('123456\rabc')
    abc456

    In [2]:

<强>2。python.exe

    Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print('123456\rabc')
    abc456
    >>>

3岁。崇高文本3

    print('123456\rabc')

I run the file test.py, and the result was this:

    123456
    abc
    [Finished in 0.1s]

4岁。PyCharm 2017.2.3 x64

I still run test.py, the result was:

    C:\Users\user\Anaconda3\python.exe C:/Users/user/Desktop/cv/test.py
abc

    Process finished with exit code 0

所以我不知道为什么这些结果不同。你知道吗


Tags: thepytestdefaultforobjectipythonbit

热门问题