习题 9: 打印,打印,打印
现在,你应该意识到这本书的模式是使用很多的练习教你一些新的东西。我以一些你可能不太理解的代码为开始,然后用更多的练习来解释这些概念。如果你不明白现在的东西,你多做些练习之后就会明白。记下你不明白什么,继续前进。
# Here's some new strange stuff, remember type it exactly.
days = "Mon Tue Wed 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.
"""
What You Should See
$ python ex9.py
Here are the days: Mon Tue Wed Thu Fri Sat Sun
Here are the months: Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
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.
Study Drills
- 自己检查结果,记录你犯过的错误,并且在下个练习中尽量不犯同样的错误。
Common Student Questions
Why do the \n newlines not work when I use %r ? |
---|
That's how %r formatting works; it prints it the way you wrote it (or close to it). It's the "raw" format for debugging. |
Why do I get an error when I put spaces between the three double-quotes? |
You have to type them like """ and not " " " , meaning with no spaces between each one. |
Is it bad that my errors are always spelling mistakes? |
Most programming errors in the beginning (and even later) are simple spelling mistakes, typos, or getting simple things out of order. |
Copyright (C) 2010 by
Author: Zed Shaw
Translator:Zander Wong