Is there any in-depth and up-to-date tutorials about the indentations used in Python?

  • IndentationError: unexpected indent
  • IndentationError: expected an indented block
  • TabError: inconsistent use of tabs and spaces in indentation

Your post is sufficient enough.

The only hard and fast rule is that indentations must be consistent. Most editors will default to one four-space tab, or to four spaces, and will give you the option to choose for yourself. Mixing tabs and spaces is frowned upon, and will often cause an error.

The editor here at CodeAcademy, however, uses two spaces. To keep it happy, you should consistently use two spaces, and avoid tabs altogether.

The editor will automatically indent the proper amount if you press Enter following a colon :.
That is where an “indented block” is expected.

One backspace will de-indent two spaces, i.e., the proper amount to go to the next level out.

It takes a bit of practice. The main problem I have found is in copying and pasting code from or into a different editor.

2 Likes