+ 15
What does the return statement in python do
29 Answers
+ 22
It returns a value such that when the function is called, the value is returned.
+ 13
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.
+ 6
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. ☀️☀️
+ 6
Even if you don't use "return" a None-Type object is returned by default.
+ 4
It assigns the current result to the function and terminates further iteration but does not print the result.
+ 2
And returns program flow to the point just after where the function was called from.
+ 2
Lets say that your code looks like this:
def Hello():
x = print("hello")
return x
a = Hello()
a
print(a)
a will be equal to "print("hello")
basically it does what its say
+ 2
This is a question that needs to be rephrased replacing "Python" with "ANY". It takes you out of the program like an EXIT condition.
+ 1
It returns the valur of the function
0
Return statement give results that can store in variables
0
It returns the value that you have given for that function and exits from that function.
0
it returns value for future use. It can be accessed later other than that function.
0
It returns the output of your function routine.
Like you can check if your routine succeeded by returning a boolean (true or false) or return the output of some math
0
The Python return statement is a special statement that you can use inside a function or method to send the function's result back to the caller. A return statement consists of the return keyword followed by an optional return value. The return value of a Python function can be any Python object.
0
Returns values above it
0
return the value of the function
- 1
Basically when you write a function
Def addTwoNums(a, b):
return a + b
print(addTwoNums(1, 2))
Result: 3
This is because when called the function and put in two parameters, the function will return the sum of the two, and then we print it to the screen which is also three so therefore, you have three
- 1
Return is as it's named, it will exist you from a function with or without value.
The value could be anything. Like:
def some_function():
return 3+2
print (some_function())
- 1
A return statement ends the execution of the function call and "returns" the result, i.e. the value of the expression following the return keyword, to the caller.
- 1
Return statement in python like other programming languages is use to return a defined value or command in a function when it's been called