Can print() be reloaded for a user defined class?

Peng Yu pengyu.ut at
Sun Sep 20 17:16:56 CEST 2009

On Sun, Sep 20, 2009 at 9:19 AM, Dave Angel <davea at> wrote:
> Peng Yu wrote:
>> <snip>
>>> you might use:
>> Is __repr__ =_str__ copy by reference or by value? If I change
>> __str__ later on, will __repr__ be changed automatically?
>> Regards,
>> Peng
> Reference or value?  Neither one.  This assignment is no different than any
> other attribute assignment in Python.  Technically, it binds the name
> __repr__ to the function object already bound by __str__.  You now have a
> second name pointing to the same object.  Rebinding one of those names  to
> yet another different object won't affect the other name.
> name1 = "this is a test"
> name2 = name1
> name1 = "another string"           #this has no effect on name2
> print name1, name2

I am more familiar with C++ than python. So I need to connect python
concept to C++ concept so that I can understand it better.

name1 and name are all references (in the C++ sense), right?

__repr__  and __str__ are references (in the C++ sense) to functions
and both of them could refer to the same function or two different
ones, right?


More information about the Python-list mailing list