-2
                        if CheckRadioHigh is True:
                            Higher_Lower = 'Higher'
                        elif CheckRadioLower is True:
                            Higher_Lower = 'Lower'
                        else:
                            Higher_Lower = ''

I want to write this line of code in one line / short hand format.

  • 1
    Does https://stackoverflow.com/questions/14029245/putting-an-if-elif-else-statement-on-one-line this answer your question? – Saurav Rai Feb 12 '20 at 14:09

2 Answers2

2

Can do this by nesting if-else oneliners:

Higher_Lower = 'Higher' if CheckRadioHigh else ('Lower' if CheckRadioLower else '')

Please note: You do not have to explicitly check a boolean variable if it is True or is False in if statements. Just make use of the content of the variable by checking if <boolean variable>.

AnsFourtyTwo
  • 2,480
  • 2
  • 13
  • 33
2
Higher_Lower = 'Higher' if CheckRadioHigh else 'Lower' if CheckRadioLower else 'Do some searching buddy :)'
niths4u
  • 440
  • 3
  • 13