执行代码后,我得到以下打印输出:
"Het antwoord van de berekening is: 8775 ."
当我想得到“安特伍德范德贝雷肯是:8775。”。所以我想去掉数字和点之间的空格。我该怎么做?你知道吗
Berekening1 = 8.5
Berekening2 = 8.1+4.8
Berekening3 = 8*10
Berekening4 = 3
x = Berekening1 * Berekening2 * Berekening3 + Berekening4
print "Het antwoord van de berekening is:",
print int(x),
print "."
您可以使用:
不要使用
print ..,
,它会添加空格,因为你让它用逗号。改用字符串格式:这里的
{}
是一个占位符,一个将第一个参数放入str.format()
方法的槽。.
紧跟其后:您也可以使用字符串连接,但这更麻烦:
你不想用Python3吗?在python3中,
print
是一个函数,它接受可选的关键字参数,可以根据您的需要修改其行为这如何适用于你的问题(或者说,老实说,根据Padraic的评论,你对成为你问题的任务的特定方法)?你有两种可能
如果您还停留在python2中,那么仍然可以利用
print
作为函数从__future__
导入此行为,使用在你的程序里。你知道吗
如果你不太了解这些东西,SO is your friend
相关问题 更多 >
编程相关推荐