1. 程式人生 > >笨辦法學Python(八)

笨辦法學Python(八)

ould 出現 pla .net 結果 alt 練習 -1 display

習題 8: 打印,打印

技術分享
 1 formatter = "%r %r %r %r" 
 2 
 3 print formatter % (1, 2, 3, 4) 
 4 print formatter % ("one", "two", "three", "four") 
 5 print formatter % (True, False, False, True) 
 6 print formatter % (formatter, formatter, formatter, formatter) 
 7 print formatter % ( 
 8     "I had this thing.
", 9 "That you could type up right.", 10 "But it didn‘t sing.", 11 "So I said goodnight." 12 )
View Code

你應該看到的結果:

技術分享

加分習題

  1. 自己檢查結果,記錄你犯過的錯誤,並且在下個練習中盡量不犯同樣的錯誤。

  2. 註意最後一行程序中既有單引號又有雙引號,你覺得它是如何工作的?

習題練習

2.

雙引號,單引號使用問題:單引號可括雙引號,雙引號可括單引號,但是單引號不可擴單引號,雙引號亦不可括雙引號,否則報錯。

技術分享

技術分享

關於單雙引號顯示參考:

http://blog.csdn.net/wusuopubupt/article/details/23678291

對於 %r 輸出時自動添加引號,我認為默認輸出添加單引號,如果字符裏出現單引號,則輸出時添加雙引號。

技術分享

技術分享

笨辦法學Python(八)