Indentation in Python
In Python, indentation is used to define blocks of code. It tells the Python interpreter that a group of statements belongs to a specific block. All statements with the same level of indentation are considered part of the same block. Indentation is achieved using whitespace (spaces or tabs) at the beginning of each line.
For Example:
if 10 > 5:
print("This is true!")
print("I am tab indentation")
print("I have no indentation")
Output
This is true! I am tab indentation I have no indentation
- The first two print statements are indented by 4 spaces, so they belong to the if block.
- The third print statement is not indented, so it is outside the if block.

If we Skip Indentation, Python will throw error.
if 10>5:
print("GeeksforGeeks")

Indentation in Conditional Statements
The lines print(âGeeksforGeeksâĻâ) and print(âretype the URL.â) are two separate code blocks. The two blocks of code in our example if-statement are both indented four spaces. The final print(âAll set!â) is not indented, so it does not belong to the else block.
a = 20
if a >= 18:
print('GeeksforGeeks...')
else:
print('retype the URL.')
print('All set !')
Output
GeeksforGeeks... All set !
Indentation in Loops
To indicate a block of code in Python, we must indent each line of the block by the same whitespace. The two lines of code in the while loop are both indented four spaces. It is required for indicating what block of code a statement belongs to.
j = 1
while(j<= 5):
print(j)
j = j + 1
Output
1 2 3 4 5