Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A(object):
- def __init__(self, favorite_color):
- self.favorite_color = favorite_color
- #I know B will get invoked next (because it comes after me in C's parent list), so I will supply its needed argument
- super().__init__(self.favorite_color + " peppers")
- class B(object):
- def __init__(self, favorite_pizza_topping):
- self.favorite_pizza_topping = favorite_pizza_topping
- #no need to call super here, since there's nothing important after me in the mro
- class C(A,B):
- pass
- x = C("red")
- print("favorite color:", x.favorite_color)
- print("favorite topping:", x.favorite_pizza_topping)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement