Why is print() not working anymore with python?

后端 未结 3 766
清歌不尽
清歌不尽 2021-01-28 03:29

in fact this should not be a problem because it\'s fairly basic. I just want to print out an array of categories, but in one line and separated by comma.

for ent         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-28 03:52

    Check categories isn't empty - that'd make it print nothing - also I'd consider changing your code to make use of the sep argument instead (depending how large categories is):

    print(*categories, sep=', ')
    

    eg:

    >>> categories = range(10)
    >>> print(*categories, sep=', ')
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    

    Then you don't have to worry about flushing/trailing separators etc...

提交回复
热议问题