What does the return statement in python do

8/21/2019 10:07:42 PM


8 Answers

New Answer


It returns a value such that when the function is called, the value is returned.


In simple explanation return is used in python to exit or terminate a function and return a value. In example if you use def myfunction():   return 3+3   print("Hello, World!") print(myfunction()) We call the function myfunction() And you will notice that it only print the return value 6 and terminate there. It'll not print the remaining code after return.


And returns program flow to the point just after where the function was called from.


Even if you don't use "return" a None-Type object is returned by default.


Frankly it does exactly what it does in any other programming language, which is exit a subroutine or a main program. it may or may not return a value which could be a number or a list of values or a string. ☀️☀️


Return statement just gives the result of the input of that function called for. And that returned value can be stored in a variable for future reference(to use some where else) in the program. or you can directly print.


It returns the valur of the function


it calls the function