“__call__ Python” Código de respuesta

__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
pythonized

__call __ () Python

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

x = Foo()
x(1, 2, 3) # __call__
Kind Kangaroo

__call__ Python


def add(a,b):
    return a + b

Clever Capybara

Respuestas similares a “__call__ Python”

Preguntas similares a “__call__ Python”

Más respuestas relacionadas con “__call__ Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código