Conditionals
Use “if” and “else” and “elif” statements to peform logic tests.
Important to note here is the use of whitespace to indicate conditional blocks. Part of what makes python code so easy to read is that indenting is used instead of curly brackets. Be careful that you are indenting the same amount for each line in a block. While most editing apps will take care of it for you, be careful not to mix tabs and spaces.
Also, note the use of “elif” statements for multiple-case tests.
[code lang=”python”]
#conditionals
a = 43
b = 16
c = 27
if a > b:
print “a is greater than b”
else:
print “a is not greater than b”
if c >= b and c <= a:
print “c is between a and b”
else:
print “c is not between a and b”
if a < 10:
print “a is less than 10″
elif a <= 20:
print “a is between 10 and 20″
elif a <= 30:
print “a is between 20 and 30″
else:
print “a is greater than 30″
[/code]