[Tutor] mysterious object

Brian van den Broek broek at cc.umanitoba.ca
Sun Dec 18 01:07:32 CET 2005


Christopher Spears said unto the world upon 2005-12-17 17:42:
> I'm working on Exercise 4 from Part 4 from Learning
> Python.  I'm trying to write a function using **args. 
> I want to create a function that adds its arguments
> together.  Here is what I have written:
> 
> def adder(**args):
>     for x in args.keys():
>         print x
> 
> print adder()
> print "---"
> print adder(a=5)
> print "---"

<snip>

> 
> 
> Here is my output:
> 
> None
> ---
> a
> None
> ---

Hi Christopher,

all functions that terminate return a value, even if they don't have 
an explicit return statement. If they either have a bare "return" or 
no return at all, then they return None. You've put prints both in the 
functions and at the function calls. So, each time you've written 
print adder(), you've asked Python to print the return value of adder 
-- which is None.

 >>> def Noner():
	return

 >>> print Noner()
None
 >>>

Does that clear it up?

Best,

Brian vdB



More information about the Tutor mailing list