从输出 Python 2.7 中删除空格 [英] removing space from output Python 2.7

查看:59
本文介绍了从输出 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)

这篇关于从输出 Python 2.7 中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆