因为Child类继承了Parent类,继承后,Child类就拥有了Parent类的所有方法,包括pprt()方法。当调用c.pprt()时,实际上调用的是Parent类中的pprt()方法,因为c是Child类的实例,所以self指向的是Child类的实例c,但是Parent类中的pprt()方法并没有使用self中的任何属性或方法,所以输出结果是一样的。

class Parent def pprtself printselfclass ChildParent def cprtself printselfc = Childccprtcpprt上面python代码为何ccprt和cpprt结果一样。通俗易懂的说说

原文地址: https://www.cveoy.top/t/topic/b6v9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录