《Python核心編程》第二版第405頁第十三章練習 -Python核心編程答案-自己做的-

來源:互聯網
上載者:User

這是自己做的練習,可能有錯誤,歡迎討論和各種最佳化重構方案。

13-1.
程式設計。請列舉一些物件導向編程與傳統舊的程式設計形式相比的先進之處。
【答案】
物件導向編程(Object Oriented Programming,OOP,物件導向程式設計)是一種電腦編程架構。OOP的一條基本原則是電腦程式是由單個能夠起到子程式作用的單元或對象組合而成。OOP達到了軟體工程的三個主要目標:重用性、靈活性和擴充性。為了實現整體運算,每個對象都能夠接收資訊、處理資料和向其它對象發送資訊。
【注】
答案摘抄自百度百科。

13-2.
函數和方法的比較。函數和方法之間的區別是什嗎?
Functions versus Methods. What are the differences between functions and methods?
【注】
在網上對這個問題有很多討論(有的很有趣,比如提到貓和cat),如果用英文關鍵詞搜尋,答案亦很多。我的答案摘抄自本題【參考】部分的第一個連結。
【答案】
A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).

All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.

1. It is implicitly passed the object for which it was called

2. It is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data)

【參考】
http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function
http://www.wellho.net/mouth/900_Python-function-v-method.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.