4 Truth and Consequences

There are no explicit boolean types in Python. Any variable or expression can be tested for truth in an if statement. The rules for whether something is considered true or false are:

One cannot (mistakenly or deliberately) put an assignment statement inside a conditional as one can in C. For example the following is not legal Python:

if x = 0:
   print "did I really mean to write a never used print statement?"

But this is legal:

if x == 0:
   print "much better"

Questions or comments? Contact help@stsci.edu
Documented updated on 2004 Jun 1