Indentation means formatting the source code of Python. The code is the main source in any programming language.
Python needs indentation in its source code. Else during compilation it throws an errors. The purpose of this post is to explain indentation rules. Useful handy guide.
Python Example Source code

How to Find Indentation Errors in Python.
def perm(l): # Compute the list of all permutations of l if len(l) <= 1: return [l] r = [] for i in range(len(l)): s = l[:i] + l[i+1:] p = perm(s) for x in p: r.append(l[i:i+1] + x) return r
How to Avoid Indentation Errors in Python
- Check first line starts at position ‘1’
- Next line starts at first TAB, usually at 4th position
- The lines inside logical statements, must start after TAB
- This way you can fix all your indentation errors
Syntax Errors
Let us take an example of Python script.
Python py_compile command helps to validate both Indentation and Syntax Errors.

The Command You Need to Compile Python Script: myscripts.py
$python3 -m py_compile myscripts.py
Use this command to compile Python source code. The byte code is platform independent.
You can run the compiled Python code in Windows, Linux, Mac or any.
How Can you check Indentation Errors

Related Posts