Advertisement
ClearCode

deep_dive

Apr 27th, 2022
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. # def add(a,b):
  2. #   return a + b
  3.  
  4. # class Test:
  5. #   def __init__(self,add_function):
  6. #       self.add_function = add_function
  7.  
  8. # test = Test(add_function = add)
  9. # print(test.add_function(1,2))
  10.  
  11. # create a Monster class with a parameter called func, store this func as parameter
  12. class Monster:
  13.     def __init__(self,func):
  14.         self.func = func
  15.  
  16. # create another class, called Attacks, that has 4 methods:
  17. # bite, strike, slash, kick (each method just prints some text)
  18.  
  19. class Attacks:
  20.     def bite(self):
  21.         print('bite')
  22.  
  23.     def strike(self):
  24.         print('strike')
  25.  
  26.     def slash(self):
  27.         print('slash')
  28.  
  29.     def kick(self):
  30.         print('kick')
  31.  
  32. # create a monster object and give it one of the attack methods from the attack class  
  33. attacks = Attacks()
  34. monster = Monster(func = attacks.bite)
  35. monster.func()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement