If Statement in Python Programming Language

If Statement in Python Programming Language

The working and structure of if statement in Python programming language is almost the same in other programming languages.

In Python programming language the if statement is a logical expression that is used to evaluate values and returns the results base on the specified results. You can see the demo below:

Now we will break down the above if statement.

The above if statement only executes if the test expression is True otherwise it won’t run.

Recommended:  Functions in Python Programming With Examples

Below is the flow chart of Python if statement.

Python if Statement Flowchart

Flowchart-python-if-statement

 

Example of Python if Statement

When the above program executes the following result will display.

Recommended:  How To Make Basic Calculator Using Python Programming Langauge

In the above example of if statement in Python programming language we see that:

Recommended:  Variables,Data Types and Type Conversion In Python Programming Language

In our above example, the variable number is equal to 10 which is greater than 0 so our test condition becomes True and code inside of if is executed.

But in the second case where -1 is not greater than 0 so our test condition is not meet the specified condition so it becomes False and the code inside of this if statement will be skipped.

Jack Sparrow

Hay I Am Admin Of This Website. I Am Very Passionate About Computers And Technology. This Website Is The Result Of My Passion. I Love To Eliminate The Barriers That Come In Seeking Education. This Website Is The Free Source Of Learning About New Technology And Up To Date Knowledge.

This Post Has 2 Comments

  1. Great Job Sir.

    1. Thank You!

Leave a Reply

Close Menu