[Tutor] Why are arguments sometimes on the left side?
Joel Goldstick
joel.goldstick at gmail.com
Mon Sep 20 18:54:08 CEST 2010
On Mon, Sep 20, 2010 at 12:04 PM, Emile van Sebille <emile at fenx.com> wrote:
> On 9/20/2010 7:16 AM Michael Scharf said...
>
> Why is it
>> list0.extend(list1)
>> and not
>> extend(list 0, list1)
>> or
>> stri0 = stri0.strip()
>> and not
>> stri0 = strip(stri0)
>> Why have arguments on the left side at all, when usually the dot notation
>> left to right implies a hierarchical relation: file.class or class.method
>> etc.
>>
>>
> You can also have it your way...
>
> >>> def extend(*args):
> ... try:
> ... args[0].extend(*args[1:])
> ... except:
> ... raise AttributeError
> ...
> >>>
> ...
> >>>
> >>> a = []
> >>> a.extend([1,2,3])
> >>> a
> [1, 2, 3]
> >>> extend(a,[4,5,6])
> >>> a
> [1, 2, 3, 4, 5, 6]
> >>>
>
>
> Emile
>
>
That's pretty creative I think, but not sure its quite on the mark for
beginners? ;)
Anyway, I was quick with my answer. This is a good place to learn about
list and string methods:
http://docs.python.org/library/stdtypes.html#built-in-types
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100920/0c7dcb1e/attachment.html>
More information about the Tutor
mailing list