How do I keep Python print from adding newlines or spaces?

This question already has an answer here:

  • How to print without newline or space? 26 answers

  • 您可以使用:

    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:避免使用打印命令的新行

    下一篇: 如何保持Python打印不添加换行符或空格?