1.class
class name:
""documentation"
statements
or
class name(base1,base2,...):
...
Most, statements are method definitions:
def name(self,arg1,arg2,...):
May also be class variable assignments
class Stack:
def __init__(self):
self.items[]=[]
def push(self,x)
def pop(self)
x=Stack() #no 'new' operator
To inspect instanc variables, use dot notation:
x.items
2.instance variable & class variable
3.constructor & distructor
def __init__(self):
...
def __del__(self):
...
4.property descriptor
def _SetTheProperty(self,value):
def _GetTheProperty(self):
def _DelTheProperty(self):
5.inheritance
single inheritance
multiple inheritance
Name Clash Problem
6.pass
while False:
pass
pass通常用来创建一个最简单的类:
class MyEmptyClass:
pass
pass在软件设计阶段也经常用来作为TODO,提醒实现相应的实现,比如:
def initlog(*args):
pass #please implement this