Function passed as an argument returns none
rustompmody at gmail.com
Thu Oct 2 13:38:32 CEST 2014
On Thursday, October 2, 2014 1:30:03 PM UTC+5:30, Steven D'Aprano wrote:
> Chris Angelico wrote:
> > wrote:
> >> So by now you know there are 2 kinds of return:
> >> So the morals in short:
> >> 1. Stick to the return that works -- python's return statement --
> >> and avoid the return that seems to work -- the print statement
> > Please. There are not two types of return; there are two completely
> > different things here. Don't pretend that print is a bad form of
> > return. It isn't.
> I strongly agree with Chris here. The OP's problem was due to confusion
> between print and return, and the solution is to learn the difference
> between printing output to the screen and returning values from a function,
> and under what circumstances Python will automatically print said returned
> values as a convenience. Conflating the two as "2 kinds of return" is an
> invitation to even more confusion: "which was the 'good' return again?".
Right and the OP subject as well as post are essentially that conflation:
> Any idea why 'None' is getting passed even though calling the donuts(4)
> alone returns the expected value?
And further if you consider that the explanations have aided, here's the most
> * return 'Number of donuts: ',count returns a tuple like:
> ('Number of donuts: ',9)
> * To just print the string without returning it as tuple , use string
You find this understanding satisfactory??
More information about the Python-list