inheritance

Chris Angelico rosuav at gmail.com
Thu Apr 5 13:00:40 EDT 2012


On Fri, Apr 6, 2012 at 2:50 AM, yag <yagnesh at live.com> wrote:
>
> Hello,
>
> I am new to python (or to any programming language). My first post on this list,
> so please go easy. Apologies if its a FAQ.

Welcome!

> class A(object):
>    def foo(self):
>        print('printing from foo in A = ',self.a)
>
> class B(A):
>    def foo(self):
>        print('printing from foo in B = ',self.b)
>
> class C(B):
>    def foo(self):
>        print('printing from foo in C = ',self.c)

In each case, you are overriding the foo() method, so your instance
will only execute the last one. If you want to chain to the others,
you need to write your methods to do so - which is what you've done
with __init__.

Hope that helps!

Chris Angelico



More information about the Python-list mailing list