Search the difference: Why this function defenition does'nt work?
husam
h.jehadalwan at student.kun.nl
Sat Dec 22 11:23:36 EST 2001
Aahz Maruch wrote:
> 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.
>
More information about the Python-list
mailing list