好久没有学这个啦,今天有那么一点点空,学一会儿吧
Exercise 9. Printing, Printing, Printing
# 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.
""")
注意:
- 三个引号要连起来写,不能加空格
- print我试过照书上在
"""
后面换行再写,结果发现There's
那一行就会隔行再输出,不清楚为什么这样,疑为勘误
Exercise 10. What Was That?
这一节讲的就是转义字符,如何在字符串中打双引号等字符
tabby_cat = "\tI'm tabbed in."
persian_cat = "I'm split\non a line."
backslash_cat = "I'm \\ a \\ cat."
fat_cat = '''
I'll do a list:
\t* Cat food
\t* Fishies
\t* Catnip\n\t* Grass
'''
print(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)
注意:
- \n是换行
- \t是对齐
\\
是一个\