Anyone Can Code.



Jyotirmay Zamre

Python code relies on indentation which refers to the spaces at the beginning of a code line. Python uses the indentation to indicate a block of code and will give an error if the indentation is ignored.

Let's first take a look at an example where indentation is used.

    if 3 < 4:
        print('Three is less than four')
Three is less than four

You will notice here that we have used some code which you have not learnt as of now. Don't worry, all of this will be taught in the conditionals tutorial.

Now let's see what happens if we don't use indentation. You will notice that the Python interpreter gives us an IndentationError, which means that the code did not match the indentation level of the if statement

    if 3 < 4:
    print('Three is less than four').
File "", line 2 print('Three is less than four') ^ IndentationError: expected an indented block

Since Python does not use curly brackets {} to separate code within a function/loop/conditional/etc. it uses indentation to identify what code goes where. That's why while learning Python, you need to pay attention to indentation. Also note that indentation can be of several level, which we will see in later tutorials.

That's it for this tutorial! Click Next to access the next tutorial!

❮ Back

Next ❯

Copyright © 2021, Q-Programming | Created by Arjun Sodhi, Balpreet Juneja and Sammarth Kumar | Developed and Designed by Sammarth Kumar