assigning values in python and perl

J. Peng peng.kyo at
Thu Jan 17 04:34:33 CET 2008

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
def test(x):
    x = [4,5,6]

print a

$ python
[1, 2, 3]

$ cat
sub test {
    my $ref = shift;
    @$ref = (4,5,6);

my @a = (1,2,3);

print "@a";

$ perl
4 5 6

More information about the Python-list mailing list