__call__使用说明

可以使自定义类像函数一样被调用

class Entity:
'''调用实体来改变实体的位置。'''
  def __init__(self, x):
      self.x = x

  def __call__(self):
      '''改变实体的位置'''
      print('self.x:', self.x)

entity = Entity(1)
entity()

================================
output:
self.x: 1

详细资料:这里

你可能感兴趣的:(__call__使用说明)