If statement in Python

If block contains the condition, if condition is true, then the statement will execute and if the condition is not true then the statement will not execute.

Syntax :

if expression: 
    statement(s) # statements must be indented 

Block Diagram :


Python doesn't provide curly-brackets ( { } ) to indicate block of code for class, functions and control flow.

Blocks of code are denoted by line indentation, which is rigidly enforced by the python.

Generally we use tab for indentation.

Thus, in Python all the continuous lines indented with same number of spaces would form a block.


# script.py
a = 10
# check the condition
if a < 20:
    # if condition is true then print the following
    print("a is less than 20")
print("value of a is :",a)
a is less than 20
value of a is : 10

Next topic is if-else in Python


Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in

Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in


(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved