fork download
  1. class Actor(object):
  2. def __init__(self, name):
  3. self.name = name
  4. self.func = self.stand
  5.  
  6. def stand(self):
  7. print(self.name + ': ' + 'i stand still')
  8.  
  9. def move(self):
  10. print(self.name + ': ' + 'i move')
  11.  
  12. actor_list = [Actor('actor_1'), Actor('actor_2')]
  13. actor_list[1].func = actor_list[1].move
  14.  
  15. for i in actor_list:
  16. i.func()
  17.  
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
actor_1: i stand still
actor_2: i move