0

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!

Alec
  • 919
  • 2
  • 10
  • 25

1 Answers1

3

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.

Community
  • 1
  • 1
RanRag
  • 48,359
  • 38
  • 114
  • 167