python super()继承父类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python super()继承父类相关的知识,希望对你有一定的参考价值。

 

 

技术分享
class Foo(object):
  def __init__(self, frob, frotz):
    self.frobnicate = frob
    self.frotz = frotz

class Bar(Foo):
  def __init__(self, frob, frizzle):
    super(Bar,self).__init__(frob,34)
    self.frazzle = frizzle

new = Bar("hello","world")
print (new.frobnicate )
print (new.frazzle )
print (new.frotz )

>>>
hello
world
34
View Code

 

以上是关于python super()继承父类的主要内容,如果未能解决你的问题,请参考以下文章