Conditional Statements 2
Conditional Statements 2
Conditional Execution
• To write useful programs we need the ability to
check conditions and change the behaviour of the
program accordingly.
• Different conditional statements in python are:
– IF
– IF ---Else (Alternative Execution)
– IF--- ELIF---- ELSE (Chained Conditionals)
– Nested Conditionals
If Condition
• If x > 0:
print "x is positive“
• The Boolean expression after the if statement is called
the condition. If it is true, then the indented statement
gets executed. If not, nothing happens.
• Structure of If
– HEADER:
FIRST STATEMENT
...
LAST STATEMENT
If Condition