if/then/else control structures

Simple if example

x = 10 y = 20 if x > y: print "x greater than y" else: print "x less or equal than y"

If in a Loop

This combines a iteration loop with an if:

ages = [5, 66, 18, 21, 99, 35] for age in ages: print age, "is", if age > 50: print "quite old." elif age < 10: print "pretty young." else: print "average."
Source
Outgoing
Loop