error solved

Solved – SyntaxError: ‘return’ outside function


In this article, you will learn how to solve SyntaxError: ‘return’ outside function.

Let’s look at a code example that produces the same error.

def passOrFail(mark):
	if mark > 45:
		print("The mark is above passing grade")
		return True
	else: 
		print("The mark is below passing grade")
return False
# File "example.py", line 8
# SyntaxError: 'return' outside function

How to Solve SyntaxError: ‘return’ outside function

In order to solve it, you need to make sure that the return statement is properly indented to represent a block of code.

def passOrFail(mark):
    if mark > 45:
        print("The mark is above passing grade")
        return True
    else: 
        print("The mark is below passing grade")
        return False

Share on social media

//