👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
A return statement sends a value of a function to a main program. If you specify a return declaration outside of a function, you will encounter the message "SyntaxError: ’return’ external function" . Error
In this guide, we explore what the external "return" function " means and why it is triggered. We will look at an example of this error so that you can understand how to fix it in your program.
SyntaxError: external function ’return’
Return statements can only be included in a function. This is because return statements send values ‚Äã‚Äãfrom a function to a main program. Without a function to send values ‚Äã‚Äãfrom, a return statement would have no clear purpose.
Return statements are found at the end of a block of code in a function. Consider the following example:
Our return statement is the last line of code in our function. A return statement can be used in an
if statement to specify multiple potential values ‚Äã‚Äãthat a function can return.
An example scenario
We are going to write a program that calculates whether or not a student has passed a computer science test. To start with, define a function that checks if a student passed or failed. The test limit is 50 points.
Our function can return two values: True or False. If a student’s grade is greater than 50 (beyond the pass / fail limit), our program returns True. Otherwise, False is returned. Our program displays the value "Checked" regardless of the result of our if statement so that we can be sure that a vote has been verified.