sys.stdout.write in python3 adds 11 at end of string

后端 未结 2 1374
走了就别回头了
走了就别回头了 2021-01-02 23:43

Can someone explain why sys.stdout.write() appends 11 to my string?

$ python3
Python 3.4.3+ (default, Jul 28 2015, 13:17:50) 
[GCC         


        
2条回答
  •  被撕碎了的回忆
    2021-01-03 00:06

    It's NOT appended to the written string. 11 here is the return value of sys.stdout.write(), which is the number of characters written.

    See write:

    Write the string s to the stream and return the number of characters written.


    It's similar to:

    >>> def foo():
    ...     print('something', end='')
    ...     return 42
    ...
    >>> foo()
    something42
    

提交回复
热议问题