Python的super函数根据其参数不同而做不同的事情。这是使用它的不同方式的演示:
class Base(object):
    def __init__(self, val):
        self.val = val
    @classmethod
    def make_obj(cls, val):
        return cls(val+1)
class Derived(Base):
    def __init__(self, val):
        # In this super call, the second argument "self" is an object.
        # The result acts like an object of the Base class.
        super(Derived, self).__init__(val+2)
    @classmethod
    def make_obj(cls, val):
        # In this super call, the second argument "cls" is a type.
        # The result acts like the Base class itself.
        return super(Derived, cls).make_obj(val)
测试输出:
>>> b1 = Base(0)
>>> b1.val
0
>>> b2 = Base.make_obj(0)
>>> b2.val
1
>>> d1 = Derived(0)
>>> d1.val
2
>>> d2 = Derived.make_obj(0)
>>> d2.val
3
该3结果是先前改性剂的组合:1(从Base.make_obj)加上2(从Derived.__init__)。
请注意,可以super仅使用一个参数进行调用即可获取“未绑定”的超级对象,这显然没有太多用处。除非您想弄乱Python内部结构并且您真的知道自己在做什么,否则实际上没有任何理由这样做。
在Python 3中,您也可以super不带任何参数进行调用(这等效于上面函数中的调用,但是更神奇)。