Last Updated : 12 Jul, 2025
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:
Python
if 10 > 5:
print("This is true!")
print("I am tab indentation")
print("I have no indentation")
This is true! I am tab indentation I have no indentation
If we Skip Indentation, Python will throw error.
Python
if 10>5:
print("GeeksforGeeks")
Error 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.
Python
a = 20
if a >= 18:
print('GeeksforGeeks...')
else:
print('retype the URL.')
print('All set !')
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.
Python
j = 1
while(j<= 5):
print(j)
j = j + 1
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4