Using print
to “return
” values fails with nesting
- functions
- return
- newbie
The OP has a function which print
s output instead of return
ing it. They observe that in the REPL, the result is the same – the output is displayed:
>>> def foo():
... result = 5 # random value – computed by fair roll of dice!
... print(result)
...
>>> foo() # looks the same as if `return` were used
5
However, when trying to re-use the result or nesting the function, an error occurs because the function returns None
.