我想用打印格式打印字符串和数字,我想 有以下代码:
John = {'strength': 10, 'skill': 10}
character1 = "John"
strength = eval(character1)['strength']
skill = eval(character1)['skill']
print " %d " % eval(character1)['strength']
print " %d " % strength
print "$s's strength is: %d, and $s's skill is: %d" % (character1, strength, character1, skill)
print "$s's strength is: %d, and $s's skill is: %d" % character1, eval(character1)['strength'], character1, eval(character1)['skill']
前两个打印我没有错误,他们打印10,最后两个打印给我: " TypeError:%d格式:需要一个数字,而不是str"。
我不明白为什么,请指点一下,谢谢!
答案 0 :(得分:1)
这是错误:$s
应为%s
。