In article <[EMAIL PROTECTED]>, Palindrom <[EMAIL PROTECTED]> wrote:
> Hi everyone ! > > I'd like to apologize in advance for my bad english, it's not my > mother tongue... > > My girlfriend (who is a newbie in Python, but knows Perl quite well) > asked me this morning why the following code snippets didn't give the > same result : > > ### Python ### > > liste = [1,2,3] > > def foo( my_list ): Right now my_list is a local variable - since you called foo(liste), the name my_list is bound to the object liste > my_list = [] But this line doesn't modify liste, instead it binds the name my_list to a different object. If you want to modify the list that my_List points to you could do it in either of two ways: def foo1(my_liste): del my_liste[:] def foo2(my_liste): my_liste[:] = [] > foo(liste) > > print liste# she expected liste to be an empty list > > ### Perl ### > > @lst =(1,2,3); > $liste [EMAIL PROTECTED]; > foo($liste); > print "@lst\n"; > > sub foo { > my($my_list)[EMAIL PROTECTED]; > @{$my_list}=() > } > > I have to admit that I don't know how to clearly explain to her the > differences between these results. > Could someone please help us understand these difference between > Python and Perl ? > > Thanks in advance, > P4|1ndr0m -- David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list