


Let’s look at an example of indentation in python for loop. We have to increase the indentation in the for loop so that the code will be grouped together. Most of the popular programming languages use braces for indentation, so anybody coming from a different programming world finds it hard at first to adjust to the idea of using whitespaces for the indentation.It happens mostly by copying the code from online sources, Word documents, or PDF files. Since whitespaces are used for indentation, if the code is large and indentation is corrupted then it’s really tedious to fix it.Most of the Python IDEs automatically indent the code for you, so it’s very easy to write the properly indented code. Python indentation rules are very simple.In Python, it’s used for grouping, making the code automatically beautiful. You can then specify the number of spaces you want to use for each level of indentation. To indent using spaces, go to the Edit menu and select ‘Convert Indentation to Spaces’. However, you can also use spaces, which is the preferred method in Python. In most programming languages, indentation is used to properly structure the code. The most common way is to use the Tab key to indent your code.The best practice is to use 4 whitespaces for the first indentation and then keep adding additional 4 whitespaces to increase the indentation.It is preferred to use whitespaces for indentation than the tab character.It’s because text editors in Non-Unix systems behave differently and mixing them can cause the wrong indentation. You should avoid mixing tabs and whitespaces to create an indentation.The first line of Python code can’t have an indentation, it will throw IndentationError.We can’t split indentation into multiple lines using a backslash.
