Oddity with function default arguments

Sheila King sheila at spamcop.net
Sat Jun 12 03:05:37 EDT 2004


Here is something that surprised me tonight:

>>> def myfunc(x, y, a='A', *mylist):
	print x
	print y
	print a
	for item in mylist:
		print item

		
>>> myfunc(2, 5, 6, 7, 8)
2
5
6
7
8
>>> myfunc(1, 2)
1
2
A
>>> myfunc(1, 2, 3, 4, 5)
1
2
3
4
5
>>> def myfunc(x, y, *mylist, a='A'):
	
SyntaxError: invalid syntax

Why isn't the default value for a printing out when I include list
arguments?

(This is Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on
win32, if that makes a difference.)

I would suspect at first a Python bug, but maybe I'm just not "seeing"
something that I should?

-- 
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



More information about the Python-list mailing list