return
returns a value to the calling scope. print
(unless someone has done some monkey patching) pushes data to stdout. A returned value can be subsequently used from the calling scope whereas something printed is dispatched to the OS and the OS handles it accordingly.
>>> def printer(x):
... print x * 2
...
>>> def returner(x):
... return x * 2
...
>>> printer(2)
4
>>> y = printer(2)
4
>>> y is None
True
>>> returner(2)
4
>>> y = returner(2)
>>> y
4
The interactive console is a bit misleading for illustrating this since it just prints a string representation of a return value, but the difference in the value assigned to y
in the example above is illustrative. y
is None
when assigned the result of printer
because there is an implicit return None
for any function which does not have an explicit return value.