Decision Making In Python

Conditional Statements checks for a particular expression, which manipulates and gives the output as boolean values like True or false. Based on the output blocks of statements are executed.

IF statement
IF else statement
Nested IF statement

1.IF statement : IF statement will check condition, if it is true a set of statements will be executed, else no statements are executed.

IF statement Syntax of Python :

Line1 : Is the IF condition expression with colon, which indicates

the completeness of IF condition.

Line 2 : If the line 1 expression results true then, 2nd line of statement is executed.

Example :

OUTPUT:

if_condition

2.If…else statement : When if statement is checked for condition, if the boolean value is true first block of statements is executed. Else block will be executed if the boolean expression is false.

If…else statement Syntax of Python :

Line1 : Is the IF condition expression with colon, which indicates

the completeness of IF condition.

Line 2 : If the line 1 expression results true then, 2nd line of statement is executed.

Line 3 : If the line 1 expression results false then, Line 4 statement will be executed.

Example :


OUTPUT:

Python_IF_else_Example

3.Nested IF condition : Nested IF conditions are used when we evaluate a condition and that condition is returning true. After that we need to validate another condition. At this time we will be using Nested IF condition.

Nested IF Syntax of Python :

Example :

OUTPUT:

Leave a Comment

Your email address will not be published.