Advertisement
KrZeSuOo0

Praca domowa tworzenie klas

Oct 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3.  
  4. class Vegetable:
  5.     pass
  6.  
  7.  
  8. vegetable = Vegetable()
  9. print(vegetable)
  10. print(isinstance(vegetable, Vegetable))
  11. print(isinstance(vegetable, object))
  12. is_consumable = Vegetable()
  13. print(is_consumable)
  14.  
  15.  
  16. class Fruit(Vegetable):
  17.     pass
  18.  
  19.  
  20. class Root(Vegetable):
  21.     pass
  22.  
  23.  
  24. class Seed(Vegetable):
  25.     pass
  26.  
  27.  
  28. fruit = Fruit()
  29. root = Root()
  30. seed = Seed()
  31.  
  32. print(fruit, root, seed)
  33. print(isinstance(fruit, Fruit))
  34. print(isinstance(fruit, object))
  35. print(isinstance(root, Root))
  36. print(isinstance(root, object))
  37. print(isinstance(seed, Seed))
  38. print(isinstance(seed, object))
  39.  
  40.  
  41. class Citrus(Fruit, Vegetable):
  42.     pass
  43.  
  44.  
  45. class Tuber(Root, Vegetable):
  46.     pass
  47.  
  48.  
  49. class Nut(Seed, Vegetable):
  50.     pass
  51.  
  52.  
  53. orange = Citrus()
  54. potato = Tuber()
  55. cashew = Nut()
  56. print(orange, potato, cashew)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement