[Tutor] Return T/F vs print T/F

bob gailer bgailer at gmail.com
Sat Feb 4 16:08:46 CET 2012

On 2/4/2012 9:38 AM, Sivaram Neelakantan wrote:
> While trying out code, I have trouble following the difference between
> return True vs print True and the same with False.  If I use return
> for the True/False statements, nothing gets printed.  Why?

Why did you expect something to be printed?

Perhaps you are confused between what happens in the interactive window 
vs running a program?

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> def f():
...   return True
 >>> f()
 >>> def g():
...     print True
 >>> g()
 >>> print f()
 >>> print g()

In the interactive window, when you call a function,  Python displays 
the returned value.
When you run a program with a call to a function, Python does NOT 
display the returned value.

A function that does not execute a return will return None; in the 
interactive window nothing is displayed.

Is that sufficient?

Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list