python - 为什么将空格计为语法错误?

标签 python syntax-error

<分区>

我正在使用 Python 3.1 IDLE,并且发现 IDLE 将空格(我将这样标记 - _)突出显示为语法错误。我想知道是否有人知道问题出在哪里并提供解决方案。我知道它看起来不对,但下划线只是为了突出 IDLE 指出问题所在的位置。我无法弄清楚那一行和下一行的问题是什么。

    def attrSelection():
        while attrChoice!=6
            if attrChoice==1:
                attrChoice=Power
                baseAttr=int(basePow)
                attrEditor()
     _      elif attrChoice==2:
                attrChoice=Health
                baseAttr=int(baseHlth)
                attrEditor()
            elif attrChoice==3
                attrChoice=Wisdom
                baseAttr=int(baseWis)
                attrEditor()
            elif attrChoice==4:
                attrChoice=Dexterity
                baseAttr=int(baseDex)
                attrEditor()
            elif attrChoice==5:
                assignRandom()
            else:
                print('Option does not exist.  Please enter option in range 1-6.')
                attrChoice=input('Choice: ')

最佳答案

IDE 可能会将您指向此处的错误:

def attrSelection():
    while attrChoice!=6
    ...
        elif attrChoice==3
    ...

:63 之后。否则,一切看起来都很好,前提是您在列出代码时没有错过开头的缩进。

关于python - 为什么将空格计为语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23545944/

相关文章:

python - 导入类变量python

python - Tkinter 嵌套主循环

database - Oracle 变量未绑定(bind) - ORA-01008

java - main 方法中的编译错误

python - 用浮点类型的 NaN 创建空 pandas DataFrame 的优雅方法

python - 我可以使用 -m 标志运行多个模块吗?

javascript - 未捕获的语法错误 : Identifier 'myOptions' has already been declared in JavaScript

c# - 如何从一种形式访问一个类到另一种形式

MySQL 错误代码 : 1060

python - 使用带有正则表达式作为键的字典的多个正则表达式替换