Skip to content

super

请查看 Python 内建函数列表 了解更多相关 API。

说明:获取父类的代理对象。

python
def super():
    '''
    获取父类的代理对象

    :return: 当前类的父类的代理对象
    '''

def super(type, obj=None):
    '''
    获取父类的代理对象

    :param type: 要获取父类的类型
    :param obj: 对象
    :return: 获取父类的代理对象
    '''

示例:

python
class Pet:
    def speak(self):
        print('某种动物在说话')

class Cat(Pet):
    def speak(self):
        print('喵喵喵')

    def super_speak(self):
        super().speak()

cat = Cat()
cat.speak()
cat.super_speak()
super(Cat, cat).speak()