Print several values in the same line with commas

后端 未结 2 726
执念已碎
执念已碎 2021-01-25 08:14

I\'m new to python (as well as stackoverflow) and I was wondering how I could print several values with commas in between them.

I\'m very well aware of the end

相关标签:
2条回答
  • 2021-01-25 08:19
    list1 = ['1','2','3','4']  
    s = ",".join(list1) 
    print(s)
    
    0 讨论(0)
  • 2021-01-25 08:26

    print also takes a sep argument which specifies the separator between the other arguments.

    >>> print(1, 2, 3, 4, sep=',')
    1,2,3,4
    

    If you have an iterable of things to print, you can unpack it with the *args syntax.

    >>> stuff_to_print = [1, 2, 3, 4]
    >>> print(*stuff_to_print, sep=',')
    1,2,3,4
    
    0 讨论(0)
提交回复
热议问题