当我编译下面的Python代码时,我得到
IndentationError: unindent不匹配任何外部缩进级别
import sys
def Factorial(n): # Return factorial
result = 1
for i in range (1,n):
result = result * i
print "factorial is ",result
return result
Why?
当我编译下面的Python代码时,我得到
IndentationError: unindent不匹配任何外部缩进级别
import sys
def Factorial(n): # Return factorial
result = 1
for i in range (1,n):
result = result * i
print "factorial is ",result
return result
Why?
当前回答
为了它的价值,我的文档字符串缩进太多,这也抛出相同的错误
class junk:
"""docstring is indented too much"""
def fun(): return
IndentationError: unindent不匹配任何外部缩进级别
其他回答
每当我遇到这个错误时,都是因为我在编辑器中混淆了制表符和空格。
这可能是因为上面的函数没有以同样的方式缩进。 即。
class a:
def blah:
print("Hello world")
def blah1:
print("Hello world")
我正在使用Sublime Text 3与Flask项目。我修复了使用视图>缩进>选项卡宽度:4后未选择缩进使用空间的错误
为了它的价值,我的文档字符串缩进太多,这也抛出相同的错误
class junk:
"""docstring is indented too much"""
def fun(): return
IndentationError: unindent不匹配任何外部缩进级别
因为我意识到没有特定于spyder的答案,我将添加一个: 基本上,仔细查看你的if语句,并确保所有if, elif和else都有相同的间距,即它们在开始时处于同一行,如下所述:
def your_choice(answer):
if answer>5:
print("You're overaged")
elif answer<=5 and answer>1:
print("Welcome to the toddler's club!")
else:
print("No worries mate!")