0
Can any one explain return statement in python
I am a beginner im totally confused what return satement will do..., Can anyone explain detailly the difference between print and return statement... đ
2 Answers
+ 2
Print is for make text go to screen
Return is for functions like
def pwr(x, y) :
return x**y
Num=pwr(2,3)
Now num will be equal to 8 because return is for returning value to the calling statement
+ 4
Function is a block of code, that can be ran by calling its name.
When you call a function it returns (evaluates) a value to the position the function was called.
For a function to return a value it's code block needs to contain an accessible return statement, which is basically just a return keyword followed by the value you want to return.
def f():
return "tomato"
var = f()
print(var) #tomato