What are the difference between sep and end in print function?

前端 未结 4 806
南方客
南方客 2020-12-10 18:42
pets = [\'boa\', \'cat\', \'dog\']
for pet in pets:
    print(pet)

boa
cat
dog
>>> for pet in pets:
        print(pet, end=\', \')

boa, cat, dog, 
>>         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 18:57

    The following two are equivalent:

    print(*array, sep='abc')
    print('abc'.join(str(x) for x in array))
    

提交回复
热议问题