Class & Object

Class Definition

class className(Base):#如果要继承的话就写上Base,否则放空;支持重载
    #内置可继承list,dict,object,file,str,set
    def __init__(self,args):
        self.data1 = args[0]
        self.data2 = args[1]
        #pass

    def method1(self,x):
        self.data1 = x
        return x

    def method2(self,x):
        x = x+1
        self.method1(x)
        #...

super

class FooParent(object):
    def __init__(self):
        self.parent = 'I\'m the parent.'
        print ('Parent')

    def bar(self,message):
        print ("%s from Parent" % message)

class FooChild(FooParent):
    def __init__(self):
        # super(FooChild,self) 首先找到 FooChild 的父类(就是类 FooParent),然后把类 FooChild 的对象转换为类 FooParent 的对象
        super(FooChild,self).__init__()    
        print ('Child')

Rewriting Internal Methods

Refer to Numerical

Static Method

keyword: del

目前只知道作用在变量上,相当于解除引用

Last updated

Was this helpful?