[Tutor] Re: where is this returning from??

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Wed Aug 25 16:26:26 CEST 2004


Reed L. O'Brien wrote:
> OK silly question.  I am going throught a book about Python so I can 
> learn it.  Following (loosely) the book I made a script.  When I run it 
> all is as expected.  Exept when calling the first branch of the if 
> statement that calls chantTwice that calls printTwice. It always returns 
> the appropriate answer followed by \n None (outputbelow script).  I can 
> seem to find where it is getting none from!!  Can someone tell me what I 
> am missing so I can move on.  I just am not seeing it.

It took me some time to see it too.

> def chantTwice(p1,p2):
>  cat = p1 + p2
>  printTwice(cat)
> 
> def thought(name):
>  if name == noun:
>    print chantTwice(p1, p2)

Here is the problem.

> %python why.py
> What next?
> home
> this is part onethis is part two this is part onethis is part two
> None

print chantTwice does two things:
- execute the body of chantTwice, with the side effect of printing p1 
and p2 twice
- print the return value of chantTwice. Since chantTwice doesn't return 
anything, the return value is None

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Tutor mailing list