首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:不是所有在python输出中的字符串格式化过程中转换的参数

TypeError:不是所有在python输出中的字符串格式化过程中转换的参数
EN

Stack Overflow用户
提问于 2016-06-26 20:18:36
回答 1查看 119关注 0票数 0

我正在尝试使用第3版“艰难地学习python”来学习Python,并在练习8中得到一个错误。

我有pythonv2.7.11并使用以下代码

代码语言:javascript
复制
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."
)

当运行pythonex8.py时,我会得到这个错误。

代码语言:javascript
复制
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将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-26 20:21:51

$r在做什么?

代码语言:javascript
复制
formatter = "%r %r %r %r"

应该行得通!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38042800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档