Methods for printing without adding control characters in python

This question already has an answer here:

  • How to print without newline or space? 26 answers

  • Python 3.x:

    print(string, end="")
    

    Python 2.x:

    from __future__ import print_function
    print(string, end="")
    

    or

    print string,    # This way adds a space at the end.
    

    From the second answer of the duplicate question, I got this idea:

    Instead of something like this:

    >>> for i in xrange(10):
            print i,
    1 2 3 4 5 6 7 8 9 10
    

    you might be able to do this:

    >>> numbers = []
    >>> for i in xrange(10):
           numbers.append(i)
    >>> print "".join(map(str, numbers))
    12345678910
    

    I would recommend import ing print_function . Or (tongue-in-cheek answer) upgrading to Python 3.x!

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

    上一篇: 如何在前一个字符串Python的末尾打印字符串

    下一篇: 在python中不添加控制字符的打印方法