将Simple Obj-C转换为Python

时间:2012-04-15 06:04:25

标签: iphone python objective-c ios

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

return (highValue > 21) ? lowValue : highValue;

如果数字highValue大于21,则返回lowValue,如果低于21,则返回highValue。如何将其转换为Python?

谢谢!

1 个答案:

答案 0 :(得分:3)

我相信你在寻找

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

另请查看python-ternary-operator