Just for curiosity. Discovered Lambdas a few days ago. I was jus wondering if something like that can be done:
(Tried on the interpret but none of my tries seemed to work)
p = lambda x: (lambda x: x%2)/2
There's no explicit purpose. I just did'nt find a satisfactory answer. I may have misunderstood Lambdas.
(lambda x: x%2)
is a function, and dividing a function by2
doesn't make any sense. You probably want to call it and divide what the value it returned.You can use an inner lambda to return another function, based on the outer parameters:
You aren't actually calling the inner
lambda
:Note in Python 2 this example will always return
0
since the remainder from dividing by2
will be either0
or1
and integer-dividing that result by2
will result in a truncated0
.