Python error IndentationError expected an indented block

486    Asked by PeterWilkins in Python , Asked on Jul 17, 2021

I am trying to execute the following python code:

def example(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

And I get the folloeing error:

IndentationError: expected an indented block


Answered by Melany Doi

 Python requires its code to be indented and spaced properly. Never mix tabs and spaces. If you're using tabs stick to tabs and if you're using space stick to space.


Also in your code, change this part:

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

Hope this will resolve your indentationerror: expected an indented block.



Your Answer

Interviews

Parent Categories