Ex8 Printing, Printing

还是 Printing

Ex8 里,练习更复杂的 Printing 语句。Zed 提示: 复杂的代码是“纸老虎”, 一行一行写注释,把大块分成小块。

示例代码 Ex8:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
formatter = "%r %r %r %r"
print formatter % (1, 2, 3, 4)
print formatter % ("one", "two", "three", "four")
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."
    )

代码运行结果如图: 需要注意,最后的几个语句,单引号和双引号混杂显示。

小结

这次更加深入联系 “%r” 的使用方法。注意嵌套结构。

Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计