gpt4 book ai didi

python - 为什么即使没有要打印的数据,打印命令也会换行

转载 作者:太空宇宙 更新时间:2023-11-04 07:06:53 25 4
gpt4 key购买 nike

只需键入 print 只会在 python 中提供换行符。在 3.x 中键入不带括号的 print 也会产生换行符。为什么?

最佳答案

因为 the documentation这么说

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

Print objects to the text stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Since printed arguments are converted to text strings, print() cannot be used with binary mode file objects. For these, use file.write(...) instead.

Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.

Changed in version 3.3: Added the flush keyword argument.

请注意,end 默认为 '\n',这是一个新行。

关于python - 为什么即使没有要打印的数据,打印命令也会换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39212632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com