aijam
2019-01-12 19:35:39 +08:00
这是你想要的吗?
>>> def _if(predict, b1, b2):
... predict and b1()
... predict or b2()
...
>>> _if(True, lambda: print(1), lambda: print(2))
1
>>> _if(False, lambda: print(1), lambda: print(2))
2
还是想玩 lambda calculus ?
>>> _True = lambda x, y: x
>>> _False = lambda x, y: y
>>> def _if(predict, b1, b2):
... predict(b1, b2)()
...
>>> _if(_True, lambda: print(1), lambda: print(2))
1
>>> _if(_False, lambda: print(1), lambda: print(2))
2