Ex9 Printing, Printing, Printing

读书心法

进入到 Ex9 ,Zed 挑明说了这本书的组织模式: 用多个练习教授新东西。给你一段代码,自己输入,不懂的地方记下来。后续练习继续对前一个练习知识点进行训练,Zed 也会给出更多解释。 如果仍然有困惑的地方,没关系,记下来,后面的练习会进一步讲解。总之,Keep going!

示例代码 Ex9:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Here's some new strange stuff, remember type it exactly.
days = "Mon Tue Web Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"

print "Here are the days: ", days
print "Here are the months:" , months

print """
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
"""

代码运行结果:

小结

Ex9 提供了新知识: “\n”和三个双引号使用法。有两点注意事项:

  1. Print 命令下, “\n” 如果被“%r”调用,那就只会显示“\n”,而不是换行。
  2. 三引号用法“”“使用中,引号不能隔开,必须连续输入。
Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计