Python If Conditional Statement
Python If Conditional Statement
Python If Conditional Statement – Basic idea of an if condition statement is that, when the condition is satisfied,
the statements in the if block are executed, otherwise not.
Syntax – Python IF
if <condition> :
statements
Example 1 – Python If
In this example, we will write an if statement. The condition checks if product of the two numbers is 30.
Output
Note : Observe the indentation or alignment of the statements inside the if-block. Unlike programming languages
like java or c where the statements are enclosed in curly braces, python considers the alignment of statements
to consider them in the block.
If the alignment is missed out as shown in the below program, interpreter throws IndentationError.
number_1 = 5
number_2 = 6
Output
Conclusion
In this Python Tutorial, we have seen the syntax of if statement in python, a pictorial representation of working
of if statement, an example and how the indentation of the statements in an if block should be, and
IndentationError if we miss out the already discussed indentation.
Python Programming
⊩ Python Tutorial
⊩ Install Python
⊩ Python Variables
⊩ Python Comments
Control Statements
⊩ Python If
⊩ Python If Else
Python String
Functions
⊩ Python Functions
Python Collections
⊩ Python List
⊩ Python Dictionary
Advanced
⊩ Python Multithreading
Useful Resources