I know you can call a python function like this:
func(x,y,z)
but can you call a function like this?
func(x)(y)
I know you can call a python function like this:
func(x,y,z)
but can you call a function like this?
func(x)(y)
Yes, if the function returns a function object. For example:
def a(x):
def b(y):
return x + y
return b
print(a(2)(3))
outputs: 5
This is only useful if you are creating sub routines
a silly example:
a = lambda x,y: lambda z: x+y+z
a(1,1)(3)
5
Well the example does not make sense. To make sense of this we can do:
a = lambda x:lambda y:y**(1/x)
>>> a(2)(4)
2.0
>>> a(2)(16)
4.0
>>> sqrt = a(2)
>>> sqrt(4)
2.0
>>> cubert = a(3)
>>> cubert(8)
2.0