×

Indentation in Python

An indent in python is where the block of code belonging to a clause starts. An indent provides space or tab which also provides an increase in readability. All the lines of code that come under a particular indent belong to the clause before the indent.

if condition:
     ---

else:
    ---

def func():
    ---

We can simply exit the block, starting to write the code by removing the space provided by the indent.

In the below example statement 1 belongs to the if condition whereas statement 2 is just a simple line of code that does not belong to the if clause.

if condition:
     statement1 
statement2