__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
__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
__call__() python
class Foo:
def __call__(self, a, b, c):
# ...
x = Foo()
x(1, 2, 3) # __call__
def __call__
class Example:
def __init__(self):
print("Instance Created")
# Defining __call__ method
def __call__(self):
print("Instance is called via special method")
# Instance created
e = Example()
# __call__ method will be called
e()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us