python: printing horizontally rather than current default printing

前端 未结 10 2069
孤城傲影
孤城傲影 2021-02-05 06:32

I was wondering if we can print like row-wise in python.

Basically I have a loop which might go on million times and I am printing out some strategic counts in that loop

相关标签:
10条回答
  • 2021-02-05 07:10

    Python 3:

    l = [3.14, 'string', ('tuple', 'of', 'items')]
    print(', '.join(map(repr, l)))
    

    Output:

    3.14, 'string', ('tuple', 'of', 'items')
    
    0 讨论(0)
  • 2021-02-05 07:13

    For python 2:

    for x in num:
        print x,
    

    For python 3:

    for x in num:
        print(x, end = ' ')
    
    0 讨论(0)
  • 2021-02-05 07:18

    Just add a , at the end of the item you're printing.

    print x,
    # 3 4
    
    0 讨论(0)
  • 2021-02-05 07:19

    The simplest way:

    print(list(iter(x)))
    

    Output:

    [3, 4, ... and so on]
    
    0 讨论(0)
提交回复
热议问题