Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. class Foo(object):
  2. def __init__(self):
  3. pass
  4.  
  5. class Bar(Foo):
  6. def __init__(self):
  7. super().__init__()
  8.  
  9. Bar()
  10.  
  11. class Foo(object):
  12. def __init__(self):
  13. pass
  14.  
  15. class Bar(Foo):
  16. def __init__(self):
  17. super(Bar, self).__init__()
  18.  
  19. Bar()
  20.  
  21. In 2.7 use this [ super(baseclass, self).__init__() ]
  22.  
  23. class Bird(object):
  24. def __init__(self):
  25. print("Bird")
  26.  
  27. def whatIsThis(self):
  28. print("This is bird which can not swim")
  29.  
  30. class Animal(Bird):
  31. def __init__(self):
  32. super(Bird,self).__init__()
  33. print("Animal")
  34.  
  35. def whatIsThis(self):
  36. print("THis is animal which can swim")
  37.  
  38. a1 = Animal()
  39. a1.whatIsThis()
  40.  
  41. > In 3.0 or more use this [ super().__init__()]
  42.  
  43. class Bird(object):
  44. def __init__(self):
  45. print("Bird")
  46.  
  47. def whatIsThis(self):
  48. print("This is bird which can not swim")
  49.  
  50. class Animal(Bird):
  51. def __init__(self):
  52. super().__init__()
  53. print("Animal")
  54.  
  55. def whatIsThis(self):
  56. print("THis is animal which can swim")
  57.  
  58. a1 = Animal()
  59. a1.whatIsThis()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement