We now have a youtube channel. Subscribe!

Python if Statement Tutorial with examples

Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, we will be studying about the Python if Statement.

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


Following is the syntax to use if statement -

if expression:

Here, if the boolean expression evaluates to TRUE, the block of statement(s) in the if statement is executed. On the other hand, if the boolean expression evaluation is FASLE, then the first set of codes after the end of the if statement(s) is executed.

Flow Chart


Below is a short example -


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!"


Below is the output of the above example -

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

RECOMMENDED POST: Python Operators

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

Do 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.

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.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain