I want to know how we get the value returned by a function - what the python return statement actually returns.
Considering following piece of code:
If you have any doubts you can always go to Python's REPL and experiment with values and functions. There is a type()
instruction that can be used with values as well as with functions, for example:
Python 3.6.2 (default, Jul 19 2017, 13:09:21)
[GCC 7.1.1 20170622 (Red Hat 7.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo():
... y=5
... return y
...
>>> type(foo())
Regarding your foo()
function, y
is a local binding that holds the value int
. return
statement returns a value of variable y
and this binding is not known outside the foo()
function scope.