By value or by reference?

Alex Martelli aleaxit at
Tue Oct 19 21:45:21 CEST 2004

Jacek Generowicz <jacek.generowicz at> wrote:
> Here's a program that tells you the answer. Should be trivially
> translatable to many other languages.
> ========================================================================
> def passCheck(b):
>     b = 'new'
> def doesThisLanguageBindByValue(language):
>     a = 'original'
>     b = a
>     b = 'new'
>     if a == 'original':
>         print "%s assigns by value" % (language)
>     else:
>         print "%s does not assigns by value" % (language)

Can you give some examples of languages which would end up in the else
branch?  I think that with a suitably perverse operator= I might be able
to imitate this weird effect in C++, but then I think I'd have to make
the 'b = a' a copy ctor instead of an assignment (or get to such levels
of perversion that even my once-C++-addled mind reels at...;-).


More information about the Python-list mailing list