-2

While I was practising in Python, I used two different editors, VSCode and Notepad, as I had to write my program on different computers as I went out for a few weeks.

But, in Notepad, unlike VSCode, the editor didn’t make necessary indentation, so I manually indented them with spaces.

But when running the program, I encountered this error,
TabError: inconsistent use of tabs and spaces in indentation

I simply don’t know what this is, and would like someone to explain.

I saw a question on this, "inconsistent use of tabs and spaces in indentation", but in Notepad, there was no option which was mentioned in the answers.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • 2
    What part of the error message is unclear? To avoid it, when using Notepad, don't use tabs to indent the code since it's not advanced enough to convert them into spaces itself (or *always* use them and never use spaces). – martineau Jan 31 '22 at 16:30

3 Answers3

1

Python depends on having correct indentation to recognize lines within the same codeblocks. This is what keeps statements grouped together and organized in a way that Python can understand them in the correct order. While 4 spaces or 1 tab are typically seen as the commonly followed indentation practice in Python, you could realistically do whatever you wanted as long as your indentation lined up in blocks where components need to mesh. For example, using an if statement with 3 spaces of indentation will not be considered in the same codeblock as a followup else statement that has 5 spaces of indentation.

The issue you're experiencing with Notepad is a result of basic Notepad not being a very good IDE. Stick with VSCode.

Josh Bunner
  • 37
  • 1
  • 9
0

You have mixed spaces and tabs. to solve this problem, you can replace all tabs with spaces in vscode using the command: ctrl + H. Also, you can always use the online editor online_vscode

markus
  • 9
  • 1
0

This is because tab and whitespace are mixed in your code.

for i in loop:
    print(i) # with tab
    print(i) # with 4 spaces

>>> TabError: inconsistent use of tabs and spaces in indentation

This code will make exception, such as your TabError: inconsistent use of tabs and spaces in indentation due to mixed use of tab and whitespace indentations.

You have to choose one between tab and 4 spaces (it can be any number of spaces, actually).

To solve your problem in Notepad, you can replace all the 4 spaces to tab, as follows: https://www.tenforums.com/tutorials/114308-find-replace-text-notepad-windows-10-a.html

Park
  • 2,446
  • 1
  • 16
  • 25