Introducing Python © Chirag Wazir 2002 Prev   Index   Next

if

if x < 0:
    print 'Negative'
elif x == 0:
    print 'Zero'
else:
    print 'Positive'

Notes:

  1. false = None, any 0, "", [], (), {}
  2. Multiple comparison operators may be used in one expression e.g. a < b <= c
  3. The pass statement can be used when a statement is required syntactically but the program requires no action