MWZ

MINDWAREZONE

beginnerPython

Why is indentation important in Python?

Answer

Clear, interview-ready explanation

Indentation is important because Python uses whitespace to define blocks of code. Unlike many programming languages, Python does not use braces {} to mark the beginning and end of a block.  

age = 20

if age >= 18:
    print("You are eligible.")
    print("Access granted.")
            

  Incorrect indentation can produce an IndentationError or change the program’s logic:  

if age >= 18:
print("You are eligible.")
            

Python’s standard style convention recommends using four spaces for each indentation level. Tabs and spaces should not be mixed because inconsistent indentation can cause errors.