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!!!
但 sep 呢?我试着将 end 替换为 sep,但没有任何反应。但我知道 sep 用于在打印时分隔,那么我应该如何使用 sep?sep 和 end 之间有什么区别?
sep
用于分隔作为*args
传递的参数。 尝试运行print('a', 'b', 'c', sep=', ')
。 - vaultah