[Tutor] 'None' output after arbitrary agruments function

André Roberge andre.roberge at ns.sympatico.ca
Thu Sep 9 12:14:52 CEST 2004


adder doesn't return a value (hence, printing it returns none).
Try the following (just calling adder, not printing it):

  def adder(*arg):
  	x = arg[0]
  	for y in arg[1:]:
  		x = x + y
  	print x

adder('abc', 'def')
adder(['aa', 'bb', 'cc'], ['dd', 'ee', 'ff'])
adder(3.23, 1.77, 3.32)

--
Andre Roberge

(Warning: I'm a newbie; this is my first contribution to Tutor-list :-)

> 
> This is probably a very basic question. I am learning about functions
> and do soem exercises. I do not understand why the following code 
> 
> def adder(*arg): 
> 	x = arg[0]
> 	for y in arg[1:]:
> 		x = x + y
> 	print x
> 
> print adder('abc', 'def')
> print adder(['aa', 'bb', 'cc'], ['dd', 'ee', 'ff'])
> print adder(3.23, 1.77, 3.32)
> 


More information about the Tutor mailing list