[Tutor] Why are arguments sometimes on the left side?

Emile van Sebille emile at fenx.com
Mon Sep 20 18:04:39 CEST 2010


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




More information about the Tutor mailing list