super函数的作用
super().__init__()
当子类重写父类的方法时,会覆盖父类方法,super此举是保留父类

如果属性名跟方法名相同,属性会覆盖方法

方法必须要有实例才能被调用,这叫做绑定

class Parent(object):
    def hello(self, name):
        print "开始"
        print u"%s 正在调用父类的方法..." % name


class Child(Parent):
    def hello(self, name):
        super(Child, self).hello(name)
        print "%s 正在调用子类的方法..." % name

 

相关文章:

  • 2022-02-27
  • 2021-10-31
  • 2022-12-23
  • 2021-11-13
  • 2021-11-05
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2021-09-24
相关资源
相似解决方案