Table of Contents
if elif else statements in python language
In this tutorial, we will discuss the concept of “if” “elif” “else” statements in python language.
In this post, we are going to learn how to use the if-else statements to decision making
if condition in python
if test_expression: statement(s)
Flow diagram of the if-else statement in Python
Here, first, the program evaluates the test_expression, only when the test_expresssion is true, The statement will be executed
if the test expression is false. The flow of control exit from the if body and skipped the execution
age=19 if age>18: print("you are a teen age boy") print("age is always checked") z_score=1.1; if z_score>1.00: print("your Z_score enough ") print("you can enter uyniversity")
When we executed the above program, it produces the following result
you are a teen age boy age checking is complete your Z_score enough you can enter uyniversity
python if else
If… elif…else.. statement in python are used for decision making.
Flow diagram
When the test_expression is true,body of if statement(s) is executed. When the test_expression is false, it executes else part of statements.
When we executed the above program, it produces the following result
Checking voting availability
you are allowed to voting
In the above example, age is declared and initialized as 32
The test expression is true and body of if (statement(s)) is executed and loop-control exits from the loop (else part is skipped)
python if elif else
When the test_expression3 is false, execute else part statements.
When we executed the above program, it produced the following result
When we executed the above program, it produced the following result
When we executed the above program, it produced the following result