python之新式类和经典类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python之新式类和经典类相关的知识,希望对你有一定的参考价值。
经典类
class A(): def __init__(self): print ‘this is a‘ def save(self): print "this is AAAAAAAA" class B(A): def __init__(self): print ‘this is BBBBBBBB‘ class C(A): def __init__(self): print ‘this is C‘ def save(self): print ‘this is CCCCCCCCCCCCC‘ class D(B,C): def __init__(self): print ‘this is D‘ c = D() c.save() #输入结果 this is D this is AAAAAAAA
新式类
class A(object): def __init__(self): print ‘this is a‘ def save(self): print "this is AAAAAAAA" class B(A): def __init__(self): print ‘this is BBBBBBBB‘ class C(A): def __init__(self): print ‘this is C‘ def save(self): print ‘this is CCCCCCCCCCCCC‘ class D(B,C): def __init__(self): print ‘this is D‘ c = D() c.save() #输入结果 this is D this is CCCCCCCCCCCCC
本文出自 “Dream chaser” 博客,请务必保留此出处http://dreamchaser.blog.51cto.com/7756851/1964656
以上是关于python之新式类和经典类的主要内容,如果未能解决你的问题,请参考以下文章