What Is Indentation In Python?
Indentation refers to the spaces at the starting of a line of code. While in other programming languages the indentation in code is for readability alone, the indentation in Python has much more significance.
What Is Indentation In Python?

Indentation refers to the spaces at the starting of a line of code. While in other programming languages the indentation in code is for readability alone, the indentation in Python has much more significance.
What do we need in Indentation in Python?
Simply, put an indentation helps the interpreter distinguish a block of code. A Python interpreter can be informed that a group of statements belongs to a specific block of code by using Python indentation. Any combination of these assertions is known as a block. The grouping of statements into a block might be thought of as serving a specific function. Braces are commonly used in programming languages like C, C++, and Java to define code blocks. Python employs indentation to draw attention to the code chunks. Python uses whitespace to indicate indentation. The same block of code contains all statements spaced to the right by the same amount. A block is simply indented further to the right if it needs to be more deeply nested.
What are Indentation Errors?

- If any of the spaces are not given or aren't properly aligned python will display the ‘indentation error’ as shown above.

- Also, a mismatched number of spaces with the lines inside the loop will throw the indentation error as above.

- If the spaces have been mixed with tab and spacebar spaces while providing indentation python will throw up the error as above.
EXAMPLES:
Missing out the indentation:

- Indentation is not given for the above code and so the block(for loop) will be left unindented and the following error will show up.

SOLUTION:
- Proper indentation should be provided as shown below,

Mismatching in a number of spaces in the block:

- Here the line “B.append(c)” is not having the same indentation as the line above, which throws up the indentation error as below,

SOLUTION:
- The number of spaces should be matching with all the lines in the same block and no matter how many spaces we are using but it should be constant over the block as shown below.

Inconsistent use of tab spaces in the block:

- Here the spaces given in the lines are inconsistent which includes the spaces using both tab spaces and space bar, which makes up the indentation error.
SOLUTION:
- Using uniform spaces for the indentation with either using a tab space or a space bar avoids indentation errors.