Tuesday, June 16, 2020

Python if Statement Tutorial with examples



Hello guys! Welcome back to another section of my tutorial on Python. In this tutorial guide, we will be studying about the Python if Statement.

The if statement contains a Logical expression making use of which data is compared and a decision is made based on the result of the data that is compared. 

Syntax

Following is the syntax to use if statement -

if expression:
   statement(s)

If the boolean expression evaluates to TRUE, the block of statement(s) inside the if statement is executed. If the boolean expression evaluation returns FASLE, the first set of codes after the end of the if statement(s) is executed.

Flow Chart



Example

Below is a short example -

#!/usr/bin/python

var1 = 500
if var1:
   print "1 - Got a true expression value"
   print var1

var2 = 0
if var2:
   print "2 - Got a true expression value"
   print var2
print "Welcome to Web design tutorialz!"

Output

Below is the output of the above example -

1 - Got a true expression value
500
Welcome to Web design tutorialz!

RECOMMENDED: Python Operators

Alright guys! This is where we are rounding up for this tutorial. In my next tutorial, we will be discussing about the  If...else Statements.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.
Share:

0 comments:

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.