《笨辦法學Python》 習題8

2021-09-13 19:20:22 字數 728 閱讀 1843

系統:mac os 10.14

python: 2.7.10

版本:《笨辦法學python》(第四版)

formatter = "%r %r %r %r"

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."

)

輸出結果如圖所示:

出現一次變數編輯錯誤。

最後一行的第3個字串 「but it didn』t sing.」,輸出時是雙引號,它與另外3個字串的區別在於中間多了乙個單撇號,暫理解為,若沒有單撇號,則字串輸出優先單撇號包裹,如有,則為避免歧義,輸出雙引號包裹。

《笨辦法學python》習題38 40

mystuff 然後作者又給出了乙個錯誤的情況 class thing object def test hi print hia thing a.test hello 錯誤原因是test 只可以接受乙個引數,卻給了兩個。也就是 a.test hello 實際上是test a,hello 從這裡開始到...

《笨辦法學Python》 習題3

加分習題 系統 mac os 10.14 python 2.7.10 版本 笨辦法學python 第四版 print i will now count my chickens print hens 25 30 6.0 print roosters 100 25 3 4 print now i wil...

《笨辦法學Python》 習題6

加分習題 系統 mac os 10.14 python 2.7.10 版本 笨辦法學python 第四版 x there are d types of people.10 binary binary do not don t y those who know s and those who s.bi...