笨辦法學Python(八)

來源:互聯網
上載者:User

標籤:單引號   否則   sed   mat   false   this   logs   blank   錯誤   

習題 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(八)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.