How to stop an extra trailing newline character?

This question already has an answer here:

  • How to print without newline or space? 26 answers

  • basically the newline is a result of your print printing an empty line . Take this code for example:

    >>> a = input()    # user presses enter (blank line)
    >>> a
    ''
    >>> print(a)
                       # a newline introduced by `print` function
    >>>
    

    we can however override this default behavior of print
    print as the form print([object, ...][, sep=' '][, end='n'][, file=sys.stdout])

    >>> a = ''
    >>> print(a, end='')
    >>> 
    

    To sum up, all you need to do in your code is, replace print(<somevalue>) with print(<somevalue>, end='')

    链接地址: http://www.djcxy.com/p/77230.html

    上一篇: 在python中一次/一次打印所有循环

    下一篇: 如何停止一个额外的尾随换行符?