Search the difference: Why this function defenition does'nt work?
husam
h.jehadalwan at student.kun.nl
Sat Dec 22 10:40:23 EST 2001
hi, I'm a beginner to python and try to understand some basic stuff.
Hier are two function defenitions , which look the same for me, but the
second one does not work. Can anybody explain why?
def fun1 (*args):
sum=args[0]
for next in args[1:]
sum=sum+next
return sum
print fun1('a','b','c')
>>>abc
def fun2 (*args):
sum=args[:0]
for next in args[1:]
sum=sum+next
return sum
print fun2('a','b','c')
>>> TypeError: illegal argument type for built-in operation
Thanks in advance.
PS: the first code is taken from Learning Python by Lutz & Ascher. The
second one is the one I made to solve a small educational problem.
More information about the Python-list
mailing list