This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
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
The post Solved – SyntaxError: ‘return’ outside function appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-03-07T11:07:19+00:00) Solved – SyntaxError: ‘return’ outside function. Retrieved from https://www.scien.cx/2021/03/07/solved-syntaxerror-return-outside-function/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.