assigning values in python and perl

Paddy paddy3118 at googlemail.com
Thu Jan 17 01:10:55 EST 2008


On Jan 17, 3:34 am, "J. Peng" <peng.... at gmail.com> wrote:
> 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]
>

Hi J,
Unlike C or Perl , there is hardly ever any good reason for functions
to act by purposefully modifying their arguments. Don't do it. Stick a
return in your function and use that result. It is much more
maintainable and readable. (It will also work, and look a lot more
like, the same function written in other languages :-)

- Paddy.



More information about the Python-list mailing list