Extra line in output when printing inside a loop

后端 未结 5 514
鱼传尺愫
鱼传尺愫 2021-01-11 17:33

I can\'t figure out why the code #1 returns an extra empty line while code #2 doesn\'t. Could somebody explain this? The difference is an extra comma at the end of the code

5条回答
  •  走了就别回头了
    2021-01-11 18:13

    In order to not have a blank line, you need , at the end of the print statement

    Example:

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

提交回复
热议问题