Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Base:
- def __init__(self, a, b, c=None):
- self.a = a
- self.b = b
- self.c = c
- def __str__(self):
- return '{}, {}, {}'.format(self.a, self.b, self.c)
- class Derived(Base):
- def __init__(self, a, b, c, d):
- super().__init__(a, b, c) # pass the to the Base initializer
- self.d = d # add the extra variable
- def __str__(self):
- # Here string representation of the Base part with added self.d
- return super().__str__() + ', {}'.format(self.d)
- if __name__ == '__main__':
- bas = Base(1, 2, 3)
- print(bas)
- der = Derived(1, 2, 3, 4)
- print(der)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement