我有一个我一直在开发的应用程序,但现在我需要将此行转换为 Python。
return (highValue > 21) ? lowValue : highValue;
上面说如果数字highValue大于21,返回lowValue,如果小于21,返回highValue。如何将其转换为 Python?
谢谢!
我有一个我一直在开发的应用程序,但现在我需要将此行转换为 Python。
return (highValue > 21) ? lowValue : highValue;
上面说如果数字highValue大于21,返回lowValue,如果小于21,返回highValue。如何将其转换为 Python?
谢谢!
我相信你正在寻找
>>> highvalue = 25
>>> lowvalue = 21
>>> def myfunc():
... return lowvalue if highvalue>21 else highvalue
...
>>> myfunc()
21
>>>
也看看这里python-ternary-operator。