EX6
一、作業(yè)內(nèi)容:
我們將鍵入大量的字符串吼肥、變量、和格式化字符,并且將它們打印出來缀皱。我們還將練習(xí)使用簡(jiǎn)寫的變量
名斗这。程序員喜歡使用惱人的難度的簡(jiǎn)寫來節(jié)約打字時(shí)間,所以我們現(xiàn)在就提早學(xué)會(huì)這個(gè)啤斗,這樣你就能讀
懂并且寫出這些東西了表箭。
二、學(xué)習(xí)總結(jié):
發(fā)現(xiàn)本辦法中的東西钮莲,都是在后面逐步解釋前面的東西免钻,蠻好的。
EX7
現(xiàn)在我們將做一批練習(xí)崔拥,在練習(xí)的過程中你需要鍵入代碼极舔,并且讓它們運(yùn)行起來。我不會(huì)解釋太多链瓦,因
為這節(jié)的內(nèi)容都是以前熟悉過的拆魏。這節(jié)練習(xí)的目的是鞏固你學(xué)到的東西。我們幾個(gè)練習(xí)后再見慈俯。不要跳
過這些習(xí)題渤刃。不要復(fù)制粘貼!
二贴膘、學(xué)習(xí)總結(jié):
開始寫代碼有點(diǎn)感覺了卖子,不過還是經(jīng)常忘記某些符號(hào),應(yīng)該是鍛煉太少了步鉴。
ex8
代碼
formatter = "%r %r %r %r"#%r %s 的使用風(fēng)格不一樣揪胃,百度說%r用rper()方法處理對(duì)象,%s用str()方法處理對(duì)象氛琢,沒太理解
print(formatter % (1, 2, 3, 4))
print(formatter % ("one", "two", "three", "four"))
print(formatter % (True, False, False, True))
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."
))#第二句忘記打印喊递,然后艘油的文字就報(bào)錯(cuò),好奇為什么
總結(jié):
有時(shí)候百度阳似,也發(fā)現(xiàn)稀里糊涂的骚勘,等熟練后,應(yīng)該重新把基礎(chǔ)的理論重行看下撮奏。
ex9
代碼
# Here's some new strange stuff, remeber type it exactly.
days = "Mon Tue Wed The 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.
在打印一行中文俏讹。
""")
總結(jié):
1.剛開始看到3個(gè)雙引號(hào)很奇怪,為什么會(huì)獨(dú)立三個(gè)引號(hào)畜吊,后面看到對(duì)應(yīng)的就知道是要輸出一整套東西泽疆。
2.3個(gè)引號(hào),可以打印無數(shù)行玲献,得記住這個(gè)殉疼,下次可能用的到梯浪。
ex10
代碼
tabby_cat = "\tI'm tabbed in."#水平制表符,相當(dāng)于水平行空2格
persian_cat = "I'm split\non a line."#\n 換行符
backslash_cat = "I'm \\ a \ cat."#第一個(gè)\沒顯示瓢娜,\\只顯示一個(gè)\
fat_cat = '''
I'll do a list.
\t* Cat food
\t* Fishies
\t* Catnip\n\t* Grass
'''#\t 其實(shí)就是空2格的意思
print(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)#打印變量
總結(jié)
我把轉(zhuǎn)義序列手寫到筆記本上了挂洛,有些的確用不到。