Python IDLE 中的反向制表符 (3.7)

Reverse Tab in Python IDLE (3.7)

在 Python IDLE 中是否有反向制表符的键盘快捷键?

我正在尝试编写 if-elif-else 语句,但无法通过反向制表符正确缩进 elif 语句。我试过 shift+tab 和 shift+ctrl+tab。

比如我可以这样写...

if x < 0:
    print('Less than Zero')

但是当我尝试添加 elif 语句时...

elif x == 0:
    print('Zero')

我收到以下错误消息:

SyntaxError: unindent does not match any outer indentation level        

ctrl+[ 去除高亮代码的缩进。 ctrl+] 缩进。

如果您查看编辑器顶部的 "Edit" 菜单,您可以看到所有快捷方式。

你做的是Spyder上的快捷方式,不是,闲置时,你要做的是:

Ctrl+[

相反的是:

Ctrl+]

反向

ctrl+[

对方

ctrl+]

使用后退 space 键缩进。如果在输入任何代码之前这样做是最简单的。如果该行已经有代码,请将编辑光标放在缩进的末尾和代码的开头之间,然后再回击space。请注意,在 IDLE 中,输入和编辑并提交完整的语句以供执行。因此没有二次提示。示例:

>>> a, x, y = 1, 2, 3  # Bind some names.  This is one statement.
>>> if a:  # When you hit return, IDLE see that you entered the header
           # of a compound statement and indents the next line with a Tab.
           # Note that I have to use 8 spaces here instead of a tab.
        print(x)  # When you hit return, IDLE keeps the same indent.
                  # Use Backspace [<--] to dedent back to the margin.
else:   # Do not line up 'else' with 'if' by adding 4 spaces.
        # Since this is another header, an indent is added on the next line.
        print(y)  # No header, indent kept the same.
        # Hit Return to enter blank line

最后的空白行表示复合语句已完成,应该执行。在此之前,您可以编辑声明的任何部分。

我有点吃惊,竟然有 3 个人提出了选择行或至少缩进并使用 control-[ 的笨拙且困难得多的解决方法。我正在考虑如何使简单的方法更明显。

我知道 'if'、'elif' 和 'else' 没有排成一行很麻烦。我打算解决这个问题。