Python: Conditional expression or C ternary select

Articles may may have files attached at the end of the post

Conditional expressions in python does not have the same syntax than in C.
Python uses the and and or statements instead of the a ? b : c .

This code sample shows how to get the same result in python.

  1. #!/usr/bin/env python
  2.  
  3. a = 3
  4. print "a = 3 =>"
  5. print "a is ",
  6. print (a > 3) and "higher than 3" or "lower or equal to 3"
  7. print "and"
  8. print "a is ",
  9. print (a >= 3) and "higher or equal to 3" or "lower than 3"

will output:

$  ./conditional.py 
a = 3 =>
a is  lower or equal to 3
and
a is  higher or equal to 3