Inexplicable behavior in simple example of a set in a class
rosuav at gmail.com
Sun Jul 3 02:46:02 CEST 2011
On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali <saqib.ali.75 at gmail.com> wrote:
> So just out of curiosity, why does it work as I had expected when the
> member contains an integer, but not when the member contains a set?
It's not integer vs set; it's the difference between rebinding and
calling a method. It's nothing to do with object orientation; the same
happens with ordinary variables:
When you do a=2 or c=['Foobar'], you're rebinding the name to a new
object. But c.append() changes that object, so it changes it
regardless of which name you look for it by.
More information about the Python-list