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,565评论 5 6
  • 是谁来自山川湖海 却囿于昼夜厨房与爱 万能青年旅社
    柯珂KK阅读 118评论 0 0
  • 阿宽给我打来电话的时候已经是凌晨一点。 “我真的好喜欢你,答应我好不好?” 他用略带沙哑的声音在电话那头说。 那一...
    林安阅读 979评论 17 20
  • 很奇怪,动态规划和贪心算法也有很多相似之处:相同点:0,两者都用于求解最优化问题1,两者都将待求解的问题分解成若干...
    拉丁吴阅读 1,848评论 0 3
  • 读经时间: 2017年3月2日 星期四 晴 读经人员: 妈妈 读经内容: 《易经》57、58卦(复习);《诗词...
    161d968e601f阅读 84评论 0 0