no pass-values calling?

Torsten Bronger bronger at physik.rwth-aachen.de
Wed Jan 16 07:01:57 EST 2008


Hallöchen!

J. Peng writes:

> On Jan 16, 2008 2:30 PM, Steven D'Aprano
> <steven at remove.this.cybersource.com.au> wrote:
>> On Wed, 16 Jan 2008 13:59:03 +0800, J. Peng wrote:
>>
>>> How to modify the array passed to the function? I tried
>>> something like this:
>>>
>>>>>> a
>>> [1, 2, 3]
>>>>>> def mytest(x):
>>> ...   x=[4,5,6]
>>
>>
>> This line does NOT modify the list [1, 2, 3]. What it does is
>> create a new list, and assign it to the name "x". It doesn't
>> change the existing list.
>
> Sounds strange.
> In perl we can modify the variable's value like this way:
>
> $ perl -le '
>> $x=123;
>> sub test {
>>     $x=456;
>> }
>> test;
>> print $x '
> 456

But here, it is a global name rather than a parameter.  However, I
don't speak Perl.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                                      Jabber ID: bronger at jabber.org
               (See http://ime.webhop.org for further contact info.)



More information about the Python-list mailing list