[英]How do you remove the final space and new line in a printed statement in Python?
I have an assignment and part of it requires that we print a statement if the if statement we are using fails.我有一个任务,如果我们使用的 if 语句失败,它的一部分要求我们打印一个语句。 However, we need aren't supposed to include a space or a new line after the printed statement.但是,我们不需要在打印语句后包含空格或新行。
if second < first:
print('Second integer can\'t be less than the first.',end='')
will get rid of the new line but it still says that there is a space at the end.将摆脱新行,但它仍然说最后有一个空格。 I can not find any documentation that tells how to get rid of that final space.我找不到任何说明如何摆脱最终空间的文档。 It prints this它打印这个
'Second integer can't be less than the first. '
with a space when it is supposed to print应该打印时有一个空格
'Second integer can't be less than the first.'
without a space.没有空格。
If you add another print statement, you will see that there is no space after the period.如果添加另一个打印语句,您将看到句点后没有空格。
print('Second integer can\'t be less than the first.',end='')
print ('<----')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.