在python中,如果我说
print 'h'
我得到字母 h 和换行符。如果我说
print 'h',
我得到字母 h 并且没有换行符。如果我说
print 'h',
print 'm',
我得到字母 h、空格和字母 m。如何防止 Python 打印空格?
打印语句是同一循环的不同迭代,所以我不能只使用 + 运算符。
最佳答案
在 Python 3 , 使用
print('h', end='')
抑制结束线终止符,并且
print('a', 'b', 'c', sep='')
抑制项目之间的空格分隔符。见 the documentation for print
https://stackoverflow.com/questions/255147/