I don't know which blank is wrong.

Asked 2 years ago, Updated 2 years ago, 96 views

This screen is the Python 3 interaction shell screen, but when I try to break the line after typing else: at the bottom, I get an image-like error for some reason.What's wrong?

SyntaxError: inconsistent use of tabs and spaces in indication

Enter a description of the image here

python python3 python-idle

2022-09-30 19:51

1 Answers

The reason is that there is a mix of tabs and spaces to indent, as the message says, which is inconsistent.
For example, this article.
[Python error] TabError: inconsistent use of tabs and spaces indication

If it's IDLE's interaction shell (mode), this article seems to apply.
How to enter an indent - Python IDLE Basics

IDLE automatically adds "tabs" in interactive mode and "four half-width spaces" in the editor when you break a line with a compound statement.Therefore, to prevent mixing, use the same tab in interactive mode and four half-width spaces in the editor.

However, when typing, do not worry about anything and press Tab on both keyboards.

The IDLE editor is set to insert "four half-width spaces" when you press the Tab key, so you end up using only the Tab key on the keyboard.

Try entering indentation with the Tab key.

Also, the link in the above article does not seem to be directly related to the question, but I will introduce it to you because it may occur later.
How to Avoid Elif and Else Indentation Errors in Python IDLE Shell

If you are editing in the editor, the answer to this article With the IDLE editor you can use this: appears to have a resolution.

With the IDLE editor you can use this:

  • Menu Edit→Select All
  • Menu Format→Untabify Region
  • Assuming your editor has replaced 8 spaces with atab, enter 8 into the input box.
  • Hit select, and it fixes the entire document.

For more information in Japanese, see the Format menu (Shell window, Editor window) Untabbed Region.

Untabify Region
 Replace all tabs with the appropriate number of spaces.


2022-09-30 19:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.