Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78598

Re: Function passed as an argument returns none

Newsgroups comp.lang.python
Date 2014-10-02 04:38 -0700
References <mailman.14532.1412203048.18130.python-list@python.org> <6bf1fc74-e40f-41f0-88b9-e4543c731e69@googlegroups.com> <mailman.14538.1412222580.18130.python-list@python.org> <542d05f7$0$12998$c3e8da3$5496439d@news.astraweb.com>
Message-ID <0aaba2f6-dfa4-4ec1-9460-a97c65f2e0eb@googlegroups.com> (permalink)
Subject Re: Function passed as an argument returns none
From Rustom Mody <rustompmody@gmail.com>

Show all headers | View raw


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
recent 'conclusion':

> * 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
> formatting. 

You find this understanding satisfactory??

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Function passed as an argument returns none Shiva <shivaji_tn@yahoo.com> - 2014-10-01 22:37 +0000
  Re: Function passed as an argument returns none Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-02 00:23 +0000
  Re: Function passed as an argument returns none Rustom Mody <rustompmody@gmail.com> - 2014-10-01 19:29 -0700
    Re: Function passed as an argument returns none Chris Angelico <rosuav@gmail.com> - 2014-10-02 14:02 +1000
      Re: Function passed as an argument returns none Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-02 17:59 +1000
        Re: Function passed as an argument returns none cl@isbd.net - 2014-10-02 10:43 +0100
          Re: Function passed as an argument returns none Rustom Mody <rustompmody@gmail.com> - 2014-10-02 04:30 -0700
        Re: Function passed as an argument returns none Rustom Mody <rustompmody@gmail.com> - 2014-10-02 04:38 -0700
          Re: Function passed as an argument returns none Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-03 10:10 +1000
            Re: Function passed as an argument returns none Rustom Mody <rustompmody@gmail.com> - 2014-10-02 18:49 -0700
              Re: Function passed as an argument returns none Chris Angelico <rosuav@gmail.com> - 2014-10-03 12:08 +1000

csiph-web