简体   繁体   English

“ print x”,在Python3中等效

[英]“print x,” equivalent in Python3

Basically, I want to print out a string of values in a single line, in Python2 a statement like this one would suffice: 基本上,我想在一行中打印出一串值,在Python2中,这样的语句就足够了:

print x,

How to write the same simple statement in Python3 (ie, without using any special formatting) ? 如何在Python3中编写相同的简单语句(即,不使用任何特殊格式)?

>>> print(1, end=' '); print(2)
1 2

For further enlightenment: 进一步的启示:

>>> help(print)

Here is an explanation from the following site: 以下是来自以下站点的说明:

http://docs.python.org/release/3.0.1/whatsnew/3.0.html http://docs.python.org/release/3.0.1/whatsnew/3.0.html

See the section called "Print Is A Function." 请参阅“打印是功能”一节。

Old: print x, # Trailing comma suppresses newline 旧:打印x,#尾部的逗号禁止换行

New: print(x, end=" ") # Appends a space instead of a newline 新增:print(x,end =“”)#附加空格而不是换行符

In Python 3.x you would say: 在Python 3.x中,您会说:

print(x, end='')

Not sure what you mean by 'special formatting'. 不知道“特殊格式”是什么意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM