7

打印没有换行符或空格的变量 python3 通过 print (x,end='') 如何在 python 2.5 中执行

4

2 回答 2

11

sys.stdout.write除非指定,否则(仅)写入不带换行符的字符串。

>>> x = 4
>>> print x
4
>>> import sys
>>> sys.stdout.write(str(x)) # you have to str() your variables
4>>> # <- no newline
于 2010-10-02T17:36:01.620 回答
0

简单的:

print x,

注意最后的逗号。

于 2010-10-02T17:34:58.360 回答