Important Notice:

Indentation Error

Indentation Error

20 views 1 min read

Indentation Error (इंडेंटेशन त्रुटि) :-

Python में Indentation (Space या Tab) का उपयोग Code Block (कोड ब्लॉक) को दर्शाने के लिए किया जाता है। यदि किसी Block (जैसे if, for, while, def आदि) के अंदर सही Indentation नहीं दी जाती, तो Python IndentationError दिखाता है।

English:

In Python, Indentation (spaces or tabs) is used to define a code block. If the code inside a block (such as if, for, while, def, etc.) is not properly indented, Python raises an IndentationError.

 

Wrong Example 1: Missing Indentation -

 
if 5 > 2:
print("Five is greater than two")
 

Output:

 
IndentationError: expected an indented block after 'if' statement
 

Correct Example

 
if 5 > 2:
    print("Five is greater than two")
 

Output:

 
Five is greater than two
 

Wrong Example 2: Inconsistent Indentation -

 
if True:
    print("Python")
      print("Programming")
 

Output:

 
IndentationError: unexpected indent
 

Correct Example

 
if True:
    print("Python")
    print("Programming")
 

Output:

Python
Programming

Related Notes