J
J. Peng
I just thought python's way of assigning value to a variable is really
different to other language like C,perl.
Below two ways (python and perl) are called "pass by reference", but
they get different results.
Yes I'm reading 'Core python programming', I know what happened, but
just a little confused about it.
$ cat t1.py
def test(x):
x = [4,5,6]
a=[1,2,3]
test(a)
print a
$ python t1.py
[1, 2, 3]
$ cat t1.pl
sub test {
my $ref = shift;
@$ref = (4,5,6);
}
my @a = (1,2,3);
test(\@a);
print "@a";
$ perl t1.pl
4 5 6
different to other language like C,perl.
Below two ways (python and perl) are called "pass by reference", but
they get different results.
Yes I'm reading 'Core python programming', I know what happened, but
just a little confused about it.
$ cat t1.py
def test(x):
x = [4,5,6]
a=[1,2,3]
test(a)
print a
$ python t1.py
[1, 2, 3]
$ cat t1.pl
sub test {
my $ref = shift;
@$ref = (4,5,6);
}
my @a = (1,2,3);
test(\@a);
print "@a";
$ perl t1.pl
4 5 6