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. How…

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Solved – SyntaxError: ‘return’ outside function." Ariessa Norramli | Sciencx - Sunday March 7, 2021, https://www.scien.cx/2021/03/07/solved-syntaxerror-return-outside-function/
HARVARD
Ariessa Norramli | Sciencx Sunday March 7, 2021 » Solved – SyntaxError: ‘return’ outside function., viewed ,<https://www.scien.cx/2021/03/07/solved-syntaxerror-return-outside-function/>
VANCOUVER
Ariessa Norramli | Sciencx - » Solved – SyntaxError: ‘return’ outside function. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/07/solved-syntaxerror-return-outside-function/
CHICAGO
" » Solved – SyntaxError: ‘return’ outside function." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/03/07/solved-syntaxerror-return-outside-function/
IEEE
" » Solved – SyntaxError: ‘return’ outside function." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/03/07/solved-syntaxerror-return-outside-function/. [Accessed: ]
rf:citation
» Solved – SyntaxError: ‘return’ outside function | Ariessa Norramli | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.