How do I keep Python print from adding newlines or spaces?
This question already has an answer here:
您可以使用:
sys.stdout.write('h')
sys.stdout.write('m')
Just a comment. In Python 3, you will use
print('h', end='')
to suppress the endline terminator, and
print('a', 'b', 'c', sep='')
to suppress the whitespace separator between items.
Greg is right-- you can use sys.stdout.write
Perhaps, though, you should consider refactoring your algorithm to accumulate a list of <whatevers> and then
lst = ['h', 'm']
print "".join(lst)
链接地址: http://www.djcxy.com/p/77204.html
上一篇: Python:避免使用打印命令的新行