不换行输出
我该如何在控制台输出文本,而不在最后加上换行呢?
比如说:
print 'temp1'
print 'temp2'
输出结果:
temp1
temp2
而我需要的是:
temp1temp2
6 个回答
6
试试这个:
print 'temp1',
print 'temp2'
28
在Python 2.6以上和Python 3中:
from __future__ import print_function
print('temp1', end='')
print('temp2', end='')
37
在最后一个参数后面加一个逗号:
print 'temp1',
print 'temp2'
或者,可以使用 sys.stdout.write
来调用:
import sys
sys.stdout.write("Some output")