Conditional statement in a one line lambda function in python?

后端 未结 6 1607
借酒劲吻你
借酒劲吻你 2020-12-12 22:45

Apologies if this has been asked before, but I couldn\'t see it anywhere.

Essentially I\'ve come across a scenario where i need to make use of an if statement inside

6条回答
  •  独厮守ぢ
    2020-12-12 23:07

    By the time you say rate = lambda whatever... you've defeated the point of lambda and should just define a function. But, if you want a lambda, you can use 'and' and 'or'

    lambda(T): (T>200) and (200*exp(-T)) or (400*exp(-T))
    

提交回复
热议问题