Search the difference: Why this function defenition does'nt work?

Aahz Maruch aahz at panix.com
Sat Dec 22 10:58:12 EST 2001


In article <3C24A967.3070604 at student.kun.nl>,
husam  <h.jehadalwan at student.kun.nl> wrote:
>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

>>> l=['a','b','c']
>>> l[0]
'a'
>>> l[:0]
[]

That should be enough to figure out your problem.  Next time, try using
the interactive interpreter to test your code.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Hugs and backrubs -- I break Rule 6                 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista   

Tenth Virtual Anniversary: 9 days and counting



More information about the Python-list mailing list