Python error "IndentationError: expected an indented block"

0 votes

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
Jun 17, 2019 in Python by Rhea
2,802 views

1 answer to this question.

0 votes

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
answered Jun 17, 2019 by Varun

edited Jun 17, 2019

Related Questions In Python

+1 vote
1 answer

How to print an error in Python?

For Python 2.6 and later and Python ...READ MORE

answered Aug 23, 2018 in Python by Priyaj
• 57,510 points
389 views
0 votes
1 answer

How can I print an Error in Python?

For Python 2.6 and later and Python ...READ MORE

answered Oct 12, 2018 in Python by Aryya
• 7,350 points
77 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 548 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

Python error "TypeError: range() integer end argument expected, got numpy.float64."

Hi @Kashish, try something like this: for i ...READ MORE

answered May 27, 2019 in Python by Harish
263 views
0 votes
1 answer

How can I raise an exception in Python so that it can later be caught via an except block?

It's pretty simple to raise a query  raise ...READ MORE

answered May 29, 2019 in Python by Umesh
74 views