Code with the error

for number in range(2):
	print(number)
        print("next")

Error message (Python 3.12, last line)

TabError: inconsistent use of tabs and spaces in indentation

Corrected code

for number in range(2):
    print(number)
    print("next")

Output

0
next
1
next

Common causes

  • Part of the code was pasted from a source that uses tabs.
  • The Tab key inserts a tab character while other lines use spaces.
  • Two people edited the file with different editor settings.
  • The lines look aligned on screen because the editor draws a tab 8 or 4 spaces wide.

Practise in the course

Lesson: Loops

Frequently asked questions

How do I see where the tabs are?

Turn on “show whitespace” in your editor, or delete the indent of the line and type 4 spaces again.

Is TabError a kind of IndentationError?

Yes. It is a subtype of IndentationError, so the program does not start.