0

我有一个我一直在开发的应用程序,但现在我需要将此行转换为 Python。

return (highValue > 21) ? lowValue : highValue;

上面说如果数字highValue大于21,返回lowValue,如果小于21,返回highValue。如何将其转换为 Python?

谢谢!

4

1 回答 1

3

我相信你正在寻找

>>> highvalue = 25
>>> lowvalue = 21
>>> def myfunc():
...     return lowvalue if highvalue>21 else highvalue
...
>>> myfunc()
21
>>>

也看看这里python-ternary-operator

于 2012-04-15T06:08:12.567 回答