Conditional statement in a one line lambda function in python?

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

    In case you want to be lazier:

    #syntax lambda x : (false,true)[Condition]
    

    In your case:

    rate = lambda(T) : (400*exp(-T),200*exp(-T))[T>200]
    

提交回复
热议问题