vendredi 24 janvier 2020

boolean as if-else condition

Hi I am new to python and would like to confirm how a variable with Boolean values works in an if-else statement.

def fun(a, b, reverse):
    if reverse:
        print(b, a)
    else:
        print(a, b)

Here 'reverse' can be either True or False. So can I say it is by default that 'if reverse' is just 'if reverse is True'?

Because strictly speaking I do not see how 'if some boolean' actually fix the value of the boolean variable. (to 'if some boolean evaluates to True')

Any help is appreciated!

Aucun commentaire:

Enregistrer un commentaire