Python Class wz/wzout initialization

Simple code:

Notice of writting class:

1). Begin with 'class' keyword;

2). ALLWAYS Capitalize the First Letter of class Name;?

3). Create class instance just like calling a function.

4). Self used to attach variables and functions to a class; if the 'self' missing, then 'TypeError' occurs:

? ? ? ? ? ? TypeError: functionName() takes no arguments....

5). in Python 3.x.x , to use parenthesis '()' after 'print'; EX:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? print("something balalalalallallallalla")


Initialization:

1). Also called Constructor;

2). Function RUN when class instance created;

Example class code with 'SELF' initialization and function calls shown as below:

'Good' and 'Bad' when initialization with 'SELF' in class


To call a function within the same class
Class code with 'SELF' - Part 1
Class code with 'SELF' - Part 2
Class code without 'SELF' - Final

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,552評論 5 6
  • 是誰來自山川湖海 卻囿于晝夜廚房與愛 萬能青年旅社
    柯珂KK閱讀 118評論 0 0
  • 阿寬給我打來電話的時候已經是凌晨一點。 “我真的好喜歡你,答應我好不好?” 他用略帶沙啞的聲音在電話那頭說。 那一...
    林安閱讀 978評論 17 20
  • 很奇怪,動態規劃和貪心算法也有很多相似之處:相同點:0,兩者都用于求解最優化問題1,兩者都將待求解的問題分解成若干...
    拉丁吳閱讀 1,847評論 0 3
  • 讀經時間: 2017年3月2日 星期四 晴 讀經人員: 媽媽 讀經內容: 《易經》57、58卦(復習);《詩詞...
    161d968e601f閱讀 82評論 0 0