call python

Solutions on MaxInterview for call python by the best coders in the world

showing results for - " call python"
Luisa
15 May 2018
1#this will allow you to treat object as function
2class Test:
3  def __init__(self, num):
4    self.num = num
5  def __call__(self, inp):
6    print(self.num*inp)
7
8#create an instance of Test class
9obj = Test(5)
10obj(3) #15
11
David
24 Apr 2019
1class Foo:
2    def __call__(self, a, b, c):
3        # ...
4
5x = Foo()
6x(1, 2, 3) # __call__