[Tutor] Trouble understanding modifying parent class..

Eric Dorsey dorseye at gmail.com
Tue Apr 14 05:27:06 CEST 2009


Hi tutors, I am studying classes a bit, and am having trouble with this
concept and would appreciate your help!


class A:
    def __init__(self, name, value=1):
        self.name = name
        self.value = value

And now I want a subclass, one that overrides the value=1 and defaults to
value=2, how do I code that? I'm understanding subclasses that have
different methods that have different behavior, but I'm having trouble doing
this.

Do we have to call the __init__ of the parent somehow? Is it "replaced" or
overridden in an __init__ method of the subclass?

.. or stated simply:
If you have class A: which has def __init__(self, name, value=1), how do you
code a subclass B(A): that automatically starts with value=2?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090413/4a71d421/attachment.htm>


More information about the Tutor mailing list