[Solved] IndentationError: expected an indented block after function definition


IndentationError: expected an indented block after function definition

This error typically occurs when Python expects an indented block of code after a function definition, but the block is missing or improperly indented.

For example, consider the following program, where we have a function named addition() returning the sum of values that it received as arguments. But, as you can observe the body of the function is not indented property. But anyways, lets us go ahead and run the program.

Python Program

def addition(a, b):
return a+b

print(addition(10, 20))

Output

  File "example.py", line 2
    return a+b
    ^
IndentationError: expected an indented block after function definition on line 1

The message printed to the output clearly states that Python interpreter expected an indented block after function definition on line 1.

Solution

Let us provide proper indentation to the statements that are supposed to be given for the body of function.

Python Program

def addition(a, b):
    return a+b

print(addition(10, 20))

Output

30

Now, the program has run without any IndentationError.

Summary

In this tutorial, we learned how to solve the IndentationError that occurs when we miss the indentation for the body of a function.