IndentationError预期缩进的块 [英] IndentationError expected an indented block

查看:118
本文介绍了IndentationError预期缩进的块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

def myfirst_yoursecond(p,q):

a = p.find(" ")
b = q.find(" ")
str_p = p[0:a]
str_q = p[b+1:]

if str_p == str_q:
    result = True
else:
    result = False
return result

这是错误:

Traceback (most recent call last):
  File "vm_main.py", line 26, in <module>
    import main
  File "/tmp/vmuser_ssgopfskde/main.py", line 22
    result = False
         ^
IndentationError: expected an indented block

我的代码怎么了?

推荐答案

您混用了制表符和空格.这可能会导致一些令人困惑的错误.

You've mixed tabs and spaces. This can lead to some confusing errors.

我建议仅使用 标签或 空格进行缩进.

I'd suggest using only tabs or only spaces for indentation.

通常仅使用空格是更容易的选择.大多数编辑器都有一个选项,可以将制表符自动转换为空格.如果您的编辑器具有此选项,则将其打开.

Using only spaces is generally the easier choice. Most editors have an option for automatically converting tabs to spaces. If your editor has this option, turn it on.

顺便说一句,您的代码比它需要的更为冗长.代替这个:

As an aside, your code is more verbose than it needs to be. Instead of this:

if str_p == str_q:
    result = True
else:
    result = False
return result

只需执行以下操作:

return str_p == str_q

您在此行上似乎也有一个错误:

You also appear to have a bug on this line:

str_q = p[b+1:]

我会让你找出错误所在.

I'll leave you to figure out what the error is.

这篇关于IndentationError预期缩进的块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆