Indentation in Python (original) (raw)

Last Updated : 27 May, 2026

Indentation is used to organise and group statements into blocks of code. Unlike many other programming languages, Python uses indentation instead of braces {} to define code structure.

print("I have no Indentation ") print("I have tab Indentation ")

`

**Output

ERROR!
Traceback (most recent call last):
File "<main.py>", line 2
print("I have tab Indentation ")
IndentationError: unexpected indent

**Explanation:

Indentation in Conditional Statements

All statements in a conditional block should have same alignment.

indentation_in_python

Indentation in Python

The code below demonstrate how we use indentation to define seperate scopes of if-else statements:

Python `

a = 20

if a >= 18: print('GeeksforGeeks...') else: print('retype the URL.') print('All set !')

`

Output

GeeksforGeeks... All set !

**Explanation:

Indentation in Loops

Indentation defines the set of statements that are executed repeatedly inside a loop.

Python `

j = 1

while(j<= 5): print(j) j = j + 1

`

**Explanation: Both print(j) and j = j + 1 are indented, so they are part of the loop block. These statements keep executing until the condition j <= 5 becomes False.