Let me clarify; Let us say that you have 2 functions in Python:
def helloNot():
a = print("Heya!")
helloNot()
Which will print out Heya! without a return statement.
But if we use a return statement in this function:
def hello():
a = print("Heya!")
return a
hello()
This will print out Heya! as well.
I have read and learned that a return statement returns the result back to the function but
- doesn't the result get automatically returned by whatever result you have without a return statement inside a function?
In our case let's use the function helloNot()
(our function without the return statement):
our variable a
, which is a print statement returns the result to the function when we call it or am I missing something?
On a side note,
Why and when would we use return statements?
Is it a good habit to start using return statements?
- Are there a lot more advantages to using return statements than there are disadvantages?
EDIT:
using the print
statement was an example to better present my question. My question does NOT revolve around the print statement.
Thank you.