Answers for "__call__ in python"

2

__call__ python

#this will allow you to treat object as function
class Test:
  def __init__(self, num):
    self.num = num
  def __call__(self, inp):
    print(self.num*inp)

#create an instance of Test class
obj = Test(5)
obj(3) #15
Posted by: Guest on September-08-2021
2

__call__() python

class Foo:
    def __call__(self, a, b, c):
        # ...

x = Foo()
x(1, 2, 3) # __call__
Posted by: Guest on June-08-2020

Code answers related to "__call__ in python"

Python Answers by Framework

Browse Popular Code Answers by Language