Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78567
| From | Shiva <shivaji_tn@yahoo.com> |
|---|---|
| Subject | Function passed as an argument returns none |
| Date | 2014-10-01 22:37 +0000 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14532.1412203048.18130.python-list@python.org> (permalink) |
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:
we have 5 DN (as expected)
However if I do :
test(donuts(4), 'Number of donuts: 4')
where test is defined as below:
def test(got, expected):
print('got: ', got, 'Expected:' ,expected)
if got == expected:
prefix = ' OK '
else:
prefix = ' X '
print (('%s got: %s expected: %s') % (prefix, repr(got), repr(expected)))
Only 'None' gets passed on to parameter 'got' instead of the expected value
of 4.
Any idea why 'None' is getting passed even though calling the donuts(4)
alone returns the expected value?
Thanks,
Shiva.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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