I am trying to understand how running a python file in terminal vs running it via IDLE, for instance, may change the way the code is interpreted. I didn’t think there would be any difference, but I’ve been noticing that any “Return” commands in the code get ignored when the code is run on the mac terminal. Why is this the case?
For example, take a code as simple as the following:
def talk(arg):
return arg
talk("Hello!")
Now if I run this in terminal, I would expect it to print out “Hello!”, because it would run the function talk on the given arg “Hello!” and return it. I do get the desired result if I change the last line to print talk(“Hello!”) then it works.
The commands do get executed, but unlike in the REPL, return values in a script are not automatically printed. You will need to use
print/print()in order to actually get any output.