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()
True
>>> def g():
...     print True
...
>>> g()
True
>>> print f()
True
>>> print g()
True
None

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
919-636-4239
Chapel Hill NC

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to