Lambda inside lambda

前端 未结 3 1104
长发绾君心
长发绾君心 2021-01-18 06:54

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

3条回答
  •  情书的邮戳
    2021-01-18 07:36

    You aren't actually calling the inner lambda:

    p = lambda x: (lambda x: x%2)(x)/2
    

    Note in Python 2 this example will always return 0 since the remainder from dividing by 2 will be either 0 or 1 and integer-dividing that result by 2 will result in a truncated 0.

提交回复
热议问题