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

Steven D'Aprano steve at pearwood.info
Sat Feb 4 18:00:13 CET 2012


Sivaram Neelakantan wrote:

> def palin(text):
>     if first(text) == last(text):
>         # print first(text), last(text), middle(text), len(middle(text))
>         if len(middle(text)) == 0:
>             print True
>         else:
>             palin(middle(text))
>     else:
>         print False


Every branch of the function must include a return, or Python will just return 
None by default. You have three branches. Two of them print a flag. It is easy 
enough to fix them by changing print to return. The third branch has no 
return. It needs one.



-- 
Steven



More information about the Tutor mailing list