相关疑难解决方法(0)

打印功能中sep和end之间有什么区别?

pets = ['boa', 'cat', 'dog']
for pet in pets:
    print(pet)

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

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

boa!!! cat!!! dog!!! 
Run Code Online (Sandbox Code Playgroud)

但是怎么样?我试图用sep替换end但是什么都没发生但是我知道sep在打印时用于separete,我如何以及何时可以使用sep?sep和end之间有什么区别?

python python-2.7 python-3.x

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1