从输出 Python 2.7 中删除空格
问题描述:
elif clocked > limit and clocked <= 90:
print "Too fast! The fine is $", (clocked - limit) * 5 + 50
else:
print "Thats was extremely dangerous!\nYour fine is $", \
(clocked - limit) * 5 + 250
elif
的输出是:太快了!罚款是 50 美元.我显然想摆脱 50 美元之间的空间.我知道我可以引入一个新变量来分配我的表达式,然后格式化创建的没有空格的变量,但有什么办法可以跳过添加新的代码变量?谢谢.
Hi, the output for the elif
would like: Too fast! The fine is $ 50. I obviously want to get rid of the space between $ 50. I know I can introduce a new variable to assign my expression and then format the variable created with no spacing but is there any way around to skip adding new variable to the code? thanks.
答
您不必引入新变量即可使用字符串格式.
You don't have to introduce a new variable to use string formatting.
print "Too fast! The fine is ${0}".format((clocked - limit) * 5 + 50)