Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Conditional statements in python
  5. if-else statement in python

if-else statement in python

The if-else statement is similar to if statement except the fact that, it also provides the block of the code for the false case of the condition to be checked. If the condition provided in the if statement is false, then the else statement will be executed.

syntax:-

if conditional expression:
    Body of if
else: 
    Body of else

e.g.,

i = 25; 
if (i < 10): 
	print ("i is smaller than 10") 
else: 
	print ("i is greater than 10") 
Output- i is greater than 10

This is all about if-else statement in python.

Was this article helpful to you? Yes No

How can we help?