被导入的类

#!/usr/bin/env python class A: def __init__(self, a, b): self._a = a self._b = b def outVar(self): print self._a, self._b class B: def outVar(self): print 'b class' 

导入类

#!/usr/bin/env python from t import A, B # 从t.py中导入A,B类 a = A('a', 'b') a.outVar() b = B() b.outVar() class C(): def __init__(self): print 'C init' # del 方法:当一个实力被彻底删除,才会触发,析构函数 # python 垃圾回收机制:当一个值得引用计数为0的时候,python会自动回收 def __del__(self): print 'C del' c = C() del c # del c 不等于 c.__del__() 

关于 super

class Parent(object): def __init__(self): print "hello" class Parent1(object): def __init__(self): print "hello world" class Child(Parent1): def __init__(self): super(Child,self).__init__() #print 'hello python' c = Child() #object:继承的叫新式类 不继承的叫做经典类 #3版本:统一都继承了object 类和类型已经消失