Print several values in the same line with commas

后端 未结 2 754
执念已碎
执念已碎 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: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
    

提交回复
热议问题