我试图lambda self.status: partial if max_refundable == amount else self.status = refunded用if / else替换成一行。但是,它不能按预期方式工作。有人知道问题出在哪里吗?if max_refundable == amount: self.status = partialelse: self.status = refunded
2 回答
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
因为那是无效的语法
lambda self.status: partial if max_refundable == amount else self.status = refunded
等价于
def _lambda_func_(self.status): return partial if max_refundable == amount else self.status = refunded
这不是您想要的(self.status
不是有效的参数名称)。您不需要功能,只需执行
self.status = partial if max_refundable == amount else refunded
MMMHUHU
TA贡献1834条经验 获得超8个赞
语法如下:
a = 1
b = 3
a = a+b if a == 2 else b
在您的情况下,它看起来像这样:
self.status = partial if max_refundable == amount else refunded
添加回答
举报
0/150
提交
取消