打印特殊字符 [英] Print special characters

查看:172
本文介绍了打印特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在打印功能中打印出字符%。以下行失败。

How can I print out the character "%" in the print function. The following line fails.

print "The result is %s out of %s i.e. %d %" % (nominator, denominator, percentage)


推荐答案

通过执行 %% 可以执行c>%。所以在你的例子中,执行:

You must escape the % by doing %%. So in your example, do:

print "The result is %s out of %s i.e. %d %%" % (nominator, denominator, percentage)
#                                         ^ extra % to escape the one after

这篇关于打印特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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