Indentation & Commenting

This is part of “An intro to Python” series of posts, with content from the Enki app. If you stumbled upon this, you can start from the beginning.

Python is one of the very few programming languages that relies on the use of indentation (tabs) to work.

Usually, one indentation has four spaces in Python.

For example:

The above example returns:

If we were to rewrite the above snippet as:

The output will be:

The indentation determines whether the last call to print belongs to the else statement or whether it should be called separately from the if statement.

As a side note, indentation doesn’t matter for commented out lines. To comment out lines of code in Python, just use the hash symbol, #. For example:

Andrei Calabangiu

Content Manager

About Enki

  • AI-powered, customized 1:1 coaching
  • Fully customized to team needs
  • Pay only for active learners and results

More articles