Shorthand and nicer python syntax for four options clicking a button I have a var af_button which is a button on UI. It can be either selected or deselected, so in that case I have four possibilities, which I have implemented. I don't like this implementation, so what would be a more pythonic way of implementing this?

af_button = squishtest.waitForObject("{text='AF' type='QPushButton' unnamed='1' visible='1'}")
if state == 'click':
    if af_button.checked == 1:
        pass
    else:
        squishtest.clickButton(squishtest.waitForObject(af_button))
else:
    if af_button.checked == 0:
        pass
    else:
        squishtest.clickButton(squishtest.waitForObject(af_button))
If 0 and 1 are the only possible values of af_button.checked, you could condense this to just one if:

if (state == 'click') != af_button.checked:
    squishtest.clickButton(squishtest.waitForObject(af_button))


The parentheses are important because otherwise Python would treat this as a chained comparison. (state == 'click') evaluates to True or False, and True equals 1 and False equals 0.