Python Class wz/wzout initializa

2017-06-05  本文已影响0人  cutelittlePanda

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
上一篇下一篇

猜你喜欢

热点阅读