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."
)
输出结果:
长句输出第三行,由于句中有单引号‘,故输出时显示双引号“”
修改一些内容:
formatter = "%r %r %r %r"
print formatter % ("1", '2', 3, '''4''')
print formatter % ("one", 'two', 'three', '''four''')
print formatter % ('True', False, 1 > 2, "1 < 2")
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.'
)
输出结果:
20170914,第22课回顾修改
formatter = "%r %s %r %s"
print formatter % ("1", 2, 3, '4')
print formatter % ("one", 'two', 'three', '''four''')
print formatter % ('True', False, 1 > 2, "1 < 2")
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.'
)
输出结果: