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."
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."
)
运行后报错:
Traceback (most recent call last):
File "D:/Python27/scripts/ex8.py", line 11, in <module>
"So I said goodnight."
TypeError: not enough arguments for format string
检查后发现,少了逗号
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
)