简体   繁体   中英

Convert Simple Obj-C into Python

I have an app that I've been working on, but now I need to get this line converted into Python.

return (highValue > 21) ? lowValue : highValue;

The above says if the number highValue is greater than 21, return lowValue, and if it is lower than 21, return highValue. How can I convert this into Python?

Thanks!

I believe you are looking for

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

Also take a look here python-ternary-operator .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM