有人可以解释为什么吗sys.stdout.write()
追加11
到我的绳子?
$ python3
Python 3.4.3+ (default, Jul 28 2015, 13:17:50)
[GCC 4.9.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 'hello'
>>> y = 'world'
>>> msg = ''
>>> import sys
>>> msg += x
>>> msg += '\n' + y
>>> msg
'hello\nworld'
>>> sys.stdout.write(msg)
hello
world11
>>> print(msg)
hello
world
它不会附加到书面字符串中。11
这是返回值sys.stdout.write()
,这是写入的字符数。
See write:
写入字符串s
到流并返回写入的字符数。
它类似于:
>>> def foo():
... print('something', end='')
... return 42
...
>>> foo()
something42
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)