Google News
logo
Python if Statement
The Python if statement is same as it is with other programming languages. It executes a set of statements conditionally is true,  statement of if block is executed otherwise it is skipped.

Here is the general form of a one way if statement.
Syntax :
if expression :
    statement_1 
    statement_2
    .....
Example :
>>> a=10
>>> if a ==10:
	print("Hello F T L")

Hello F T L
>>> 

if .. else statement

In Python if .. else statement, if has two blocks, one following the expression and other following the else clause. Here is the syntax.

if else statement
Syntax :
if expression :
    statement_1
    statement_2
    ....
  else : 
   statement_3 
   statement_4
   ....

In the above case if the expression evaluates to true the same amount of indented statements(s) following if will be executed and if the expression evaluates to false the same amount of indented statements(s) following else will be executed.

Example :
>>> a=10
>>> if(a>10):
	print("Value of a is greater than 10")
else :
	print("Value of a is 10")

	
Value of a is 10
>>>