dimanche 4 décembre 2016

Python's Evaluation of If-Else Conditional Statements

I recently encountered an example of an if-else conditional statement and could not understand the rationale behind its output. The following are the statements:

if 0:
    1
else:
    2

Output: 2

I tried different integers in 0's place, and received 1 each time. Is this because the zero in the if condition represents False? But then why do integers other than 1 still satisfy the if condition?

Thanks!

Aucun commentaire:

Enregistrer un commentaire