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


Groups > comp.lang.python > #78572

Re: Function passed as an argument returns none

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.python
Subject Re: Function passed as an argument returns none
Date Thu, 2 Oct 2014 00:23:59 +0000 (UTC)
Organization A noiseless patient Spider
Lines 44
Message-ID <m0i5uv$uhi$1@dont-email.me> (permalink)
References <mailman.14532.1412203048.18130.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Thu, 2 Oct 2014 00:23:59 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="31282"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Z5RekgYA05vStyBq4UQTNd9m2pYawZd4="
User-Agent Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2)
Cancel-Lock sha1:4DPBjWepPy0ndGWb3XdTKgZCmZI=
Xref csiph.com comp.lang.python:78572

Show key headers only | View raw


On Wed, 01 Oct 2014 22:37:13 +0000, Shiva wrote:

> Hi,
> I am learning Python (version 3.4) strings.I have a function that takes
> in a parameter and prints it out as given below.
> 
> def donuts(count):
>   if count <= 5:
>     print('Number of donuts: ',count)
>   else:
>     print('Number of donuts: many') return
> 
> It works fine if I call donuts(5)
> 
> It returns:

No it doesn't

> we have 5 DN  (as expected)

It doesn't return anything, it prints something out.

Printing something out from within a function is not the same as 
returning something.

Consider the following::

def nonsense( something ):
    print( "something is", something )
    return ( 5, "elephants", { "monkey": "peanut", "baboon": 
             "banana", "numbers": ( 1, ), }, [ 1, 2, 3, 4, 5, 
             "mouse",( -6.34565e-35, 4.765213e84, ), ], 
             None, True, False, )

print( "nonsense( 10 ) is", nonsense( 10 ) )
print( "nonsense( None ) is", nonsense( None ) )
print( "nonsense( ( 5, \"donuts\", ) ) is", nonsense( ( 5, "donuts", ) ) )

The above code shows there is no automatic connection between data output 
carried out within a function and the value (if any) returned by that 
function.

-- 
Denis McMahon, denismfmcmahon@gmail.com

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