2013-01-17 48 views

回答

7

%运营商的优先级高于*/

你的意思是:

"You are at %r percent health." % (hp * 100/maxhp) 

你得到了什么是:

("You are at %r percent health." % hp) * 100/maxhp 

 

编辑:其实,我错了。它们具有相同的优先级,因此从左到右应用。

Docs: operator precedence

+0

谢谢,我从来没有告诉我们,模量被认为在这种情况下的操作,或者它的操作顺序站。我最终通过制作另一个变量并将其送入字符串来修复它。 – foltor

+0

为更正确的答案进行编辑。 –

0

需要环绕表达括号,所以它想有代入字符串结果之前充分评估。

类似:

print "my string with this '%d' value" % (hp * 100/maxhp) 
相关问题