I am trying out print and return functions in different sequences. Why does the order in the code change the output?
This is my first post so I apologise if it is badly phrased.
My first code in the longer block shown in (3) contained:
def function_that_prints():
print ("I printed")
return ("I printed")
def function_that_returns():
return ("I returned")
f1 = function_that_prints()
f2 = function_that_returns()
print (f1)
print (f2)
Result:
I printed
I printed
I returned
But it changes when you reverse them. See below.
def function_that_prints():
return ("I printed")
print ("I printed")
def function_that_returns():
return ("I returned")
f1 = function_that_prints()
f2 = function_that_returns()
print (f1)
print (f2)
Result:
I printed
I returned
Expected result:
I printed
I printed
I returned
Why ?