Python IndentationError:unindent 不匹配任何外部缩进级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46093890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python IndentationError: unindent does not match any outer indentation level
提问by Daniel
I am trying to update a dictionary value in Python. I'm trying to update a value in the dict by subtracting 3 from the value.
我正在尝试更新 Python 中的字典值。我试图通过从值中减去 3 来更新字典中的值。
if buildings == 1:
workpower -= 3
if workpower >= 0:
farmplace1 = int(input("where do you want it?"))
farmplace2 = int(input("where do you want it?"))
board[farmplace1][farmplace2] = "F"
my_dict['d'] -= 3;
I get the following error
我收到以下错误
IndentationError: unindent does not match any outer indentation level
What is wrong with the code?
代码有什么问题?
回答by AK47
Change your indentation and ensure it's consistent ( just use spaces or just use tabs, don't mix both ):
更改缩进并确保其一致(只需使用空格或仅使用制表符,不要混合使用):
if buildings == 1:
workpower -= 3
if workpower >= 0:
farmplace1 = int(input("where do you want it?"))
farmplace2 = int(input("where do you want it?"))
board[farmplace1][farmplace2] = "F"
my_dict['d'] -= 3
回答by Maksym Polshcha
Check if you use regular whitespaces for all your indents, the most likely you have tab or another space character like that instead of the whitespace.
检查所有缩进是否使用常规空格,最有可能的是制表符或其他类似的空格字符而不是空格。
Mixing space characters may lead to nice visual indents but bad for the interpreter.
混合空格字符可能会导致良好的视觉缩进,但对解释器不利。