![](/img/trans.png)
[英]python format string TypeError: not all arguments converted during string formatting
[英]TypeError: not all arguments converted during string formatting in python script output
我尝试使用“第3版学习Python困难方式”来学习python,并在练习8上遇到错误。
我有python v 2.7.11并使用以下代码
formatter = "%r %r %r $r"
print formatter % (1, 2, 3, 4)
print formatter % ("one", "two", "three", "four")
print formatter % (True, False, False, True)
print formatter % (formatter, formatter, formatter, formatter)
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
)
当运行python ex8.py时,出现此错误。
Traceback (most recent call last):
File "ex8.py", line 3, in <module>
print formatter % (1, 2, 3, 4)
TypeError: not all arguments converted during string formatting
这段代码可能是什么问题? 从我的角度来看,这正是本书中键入的内容,但是我遇到了错误。
任何帮助,将不胜感激。
此外,任何其他有助于学习python的资源也将不胜感激。
$r
在做什么?
formatter = "%r %r %r %r"
应该管用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.