如何在没有新行的情况下将文本输出到控制台?例如:
print 'temp1'
print 'temp2'
Run Code Online (Sandbox Code Playgroud)
输出:
temp1
temp2
Run Code Online (Sandbox Code Playgroud)
我需要:
temp1temp2
Run Code Online (Sandbox Code Playgroud)
SLa*_*aks 35
在最后一个参数后添加逗号:
print 'temp1',
print 'temp2'
Run Code Online (Sandbox Code Playgroud)
或者,致电sys.stdout.write:
import sys
sys.stdout.write("Some output")
Run Code Online (Sandbox Code Playgroud)
Oli*_*ier 27
在Python> 2.6和Python 3中:
from __future__ import print_function
print('temp1', end='')
print('temp2', end='')
Run Code Online (Sandbox Code Playgroud)
试试这个:
print 'temp1',
print 'temp2'
Run Code Online (Sandbox Code Playgroud)