如何在Python中删除打印语句中的最后一个空格和新行



我有一个赋值,其中一部分要求我们在使用的if语句失败时打印一个语句。然而,我们不需要在打印的声明后面包含空格或新行。

if second < first:
print('Second integer can't be less than the first.',end='')

将删除新的行,但它仍然表示末尾有一个空格。我找不到任何文件告诉如何摆脱最后的空间。它打印这个

'Second integer can't be less than the first. '

当它应该打印时有一个空格

'Second integer can't be less than the first.'

没有空间。

如果您添加另一个print语句,您将看到句点后面没有空格。

print('Second integer can't be less than the first.',end='')
print ('<----')

最新更新