Function passed as an argument returns none
steve+comp.lang.python at pearwood.info
Fri Oct 3 02:10:53 CEST 2014
Rustom Mody wrote:
> On Thursday, October 2, 2014 1:30:03 PM UTC+5:30, Steven D'Aprano wrote:
>> Chris Angelico wrote:
Restoring the attribution line you removed:
On Thu, Oct 2, 2014 at 12:29 PM, Rustom Mody <rustompmody at gmail.com>
>> >> 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?
I didn't write that. I don't know who you are quoting, but it isn't me.
> And further if you consider that the explanations have aided, here's the
> most recent 'conclusion':
>> * return 'Number of donuts: ',count returns a tuple like:
>> ('Number of donuts: ',9)
And again, despite you attributing this to me, I did not write that.
>> * To just print the string without returning it as tuple , use string
> You find this understanding satisfactory??
And that's the third time in one post that you have attributed something
written by somebody else to me.
Rustom, I don't consider this blatant misattribution of other people's words
to me is acceptable behaviour. I don't believe that somebody with your
demonstrated competence at following email and usenet quoting conventions
is unaware that you are attributing other people's comments to me. I would
be inclined to chalk it up to an innocent mistake if not for the deliberate
removal of the attribution line showing *your* advice to the OP to consider
print one of "2 kinds of return".
The original poster was confused about the difference between return and
print. You replied by reinforcing that confusion, explicitly stating that
print is a kind of return (it isn't). I don't hold that against you --
making an ill-thought-out comment in good faith is not a sin.
But in your response to my criticism of that reply, you removed the
attribution to yourself, then agreed with me ("Right") and implied that
*your* comment about there being two kinds of return was the OP's
confusion. To me, that looks like a deliberate, but feeble and pathetic,
attempt to deflect criticism of your advice to the OP onto the OP. If true,
that's a low and sordid thing to do.
Your response to Shiva, the Original Poster:
Chris' response to you, with attribution line intact:
My response to Chris, with attribution line intact:
Your response to me, with attribution line deleted, and misattributing other
people's comments to me:
More information about the Python-list