Conditional statement in a one line lambda function in python?

后端 未结 6 1595
借酒劲吻你
借酒劲吻你 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:20

    Use the exp1 if cond else exp2 syntax.

    rate = lambda T: 200*exp(-T) if T>200 else 400*exp(-T)
    

    Note you don't use return in lambda expressions.

提交回复
热议问题