Conditional Satetements, 50729
Conditional Satetements, 50729
CLASS : III-B
ROLL NO:50729
SUBJECT :PYTHON
C O N D I T I O N A L S TAT E M E N T S
o IF ELSE STATEMENT
o IF ELIF STATEMENT
o NESTED IF STATEMENT
I F - S TAT E M E N T
if the condition evaluates to True, a statement or set of statements is
executed. If the condition is False, it does nothing.
Syntax:
if <conditional statements>:
statement
[statements]
else:
statement
[statements]
I F - E L S E S TAT E M E N T
Tests a condition and if the condition evaluates to True, it carries out
statements indented below if, and in case condition evaluates to False,
it carries out statements indented below else.
Syntax :
if <conditional expression>:
statement
[statements]
else:
statement
[statements]
I F - E L I F S TAT E M E N T
A multi-way decision control statement that allows the programmer to choose one of
several possible alternatives by checking multiple conditions / expressions and executes
a set of code as soon as one that condition evaluates to True. Like else, elif statement
is also optional.
Syntax:
if <conditional expression>:
statement
[statements]
elif <conditional expression>:
statement
[statements]
else:
statement [statements]
NESTED IF STATEMENTS
A nested if is an if that has another if in its if’s body or in
elif’s body or in its else’s body
Syntax:
If(condition1)
If(condition2)
Statement1;
else:
statement2;
else:
if(condition3)
statement3;
else
statement4;
THANK YOU