Hi, I would aprreciate so much if you could help me with the following code:
def short(x, y):
short("Hello World!", "Bacon and Eggs")
I have no idea why it has no output. Plus I still haven't quite understand the return statement...
Thank you for your time!
Return statement in a function gives a value to the function that can be printed using the print statement, assigned to a variable, used in comparisons....etc
Calling a function means executing that block of code inside the function not returning its value
In your code you called the function and the code inside it was actually executed
One thing you can do is replace that return object with print(object), so that when the function is called the print function is executed
Another thing is to print the function just as maf did
Keep the return statement and try this:
a = short("Hello World!", "Bacon and Eggs")
The output will be as expected
You see how the value of the function is assigned to the variable a?
You can check that topic in the Python course for better understanding
This is a bit longer but can be understood easy:
result = short("Hello World!", "Bacon and Eggs")
How does it work: With short(...) you call the function. When function is doing "return" and gives a value back, this returned value is stored in variable result. No you can print result with print(result).