I am having difficulty in understanding the return statement in python. Can anyone give me a code or an example to let me understand..
Asked
Active
Viewed 28 times
-1
-
What kind of experience do you have in programming? In other languages? Did you read the tutorial? https://docs.python.org/3/tutorial/ – yota Oct 15 '22 at 17:46
-
i am new to python . and i have been learning it since 2 weeks. please help me if you can. i would appreciate that. – Ram chaudhary Oct 15 '22 at 17:48
-
Does this answer your question? [What is the purpose of the return statement? How is it different from printing?](https://stackoverflow.com/questions/7129285/what-is-the-purpose-of-the-return-statement-how-is-it-different-from-printing) – Gino Mempin Oct 16 '22 at 06:59
1 Answers
1
A return statement is used at the end of the function and "returns" the result of the function to the caller. For example:
def minus (x,y):
return x - y
result = minus(2,1)
print("Result: ", result)
Result: 1
NOTE : Codes after the return statement are not executed.

myrn
- 153
- 5