先贴上这几课的代码
ex8
#-*- coding:utf-8 -*-
formatter = "%s %r %r %r" #定义字符串,字符串里嵌套格式化字符串
print formatter % (1,2,3,4) # 1234会替换字符串里的%r
print formatter % ('one','two','three','four')
print formatter % (True,False,True,False)
print formatter % (formatter,formatter,formatter,formatter) #每个formatter都是一个包含四个%r的字符串
print formatter % (
"我是",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight.")
ex9
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.
"""
ex10
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
这几课的新知识是转义序列的应用
有个小问题先放在这里,\r与\n 有什么别,感觉都能实现换行的作用啊?