繁体   English   中英

TypeError:并非在python脚本输出中的字符串格式化期间转换了所有参数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM