习题 8: 打印,打印

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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
1 2 3 4
'one' 'two' 'three' 'four'
True False False True
'%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r'
'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said goodnight.'
$

加分习题

  1. 自己检查结果,记录你犯过的错误,并且在下个练习中尽量不犯同样的错误。
  2. 注意最后一行程序中既有单引号又有双引号,你觉得它是如何工作的?

Project Versions

Table Of Contents

Previous topic

习题 7: 更多打印

Next topic

习题 9: 打印,打印,打印

This Page