Advertisement
Guest User

Untitled

a guest
May 13th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class A(object):
  2. def __init__(self, favorite_color):
  3. self.favorite_color = favorite_color
  4. #I know B will get invoked next (because it comes after me in C's parent list), so I will supply its needed argument
  5. super().__init__(self.favorite_color + " peppers")
  6.  
  7. class B(object):
  8. def __init__(self, favorite_pizza_topping):
  9. self.favorite_pizza_topping = favorite_pizza_topping
  10. #no need to call super here, since there's nothing important after me in the mro
  11.  
  12. class C(A,B):
  13. pass
  14.  
  15. x = C("red")
  16. print("favorite color:", x.favorite_color)
  17. print("favorite topping:", x.favorite_pizza_topping)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement