我正在尝试使用第3版“艰难地学习python”来学习Python,并在练习8中得到一个错误。
我有pythonv2.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."
)当运行pythonex8.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将不胜感激。
发布于 2016-06-26 20:21:51
$r在做什么?
formatter = "%r %r %r %r"应该行得通!
https://stackoverflow.com/questions/38042800
复制相似问题