I'm very comfortable with .NET objects and its framework for reference vs value types. How do python objects compare to .NET objects? Specifically, I'm wondering about equality obj1 == obj2
, hash-ability (i.e. being able to put in a dict), and copying.
For instance, by default in .NET, all objects are reference types and their equality and hash code is determined by their address in memory. Additionally, assigning a variable to an existing object just makes it point to that address in memory, so there is no expensive copying occurring. It seems that this is the same for python, but I'm not entirely sure.
EDITS:
- Equality
is
checks for referential equality,==
checks for value equality (but what does value equality mean for objects?)
I was able to find some useful info from the effbot written back in 2000:
Objects
All Python objects have this:
- a unique identity (an integer, returned by
id(x)
)- a type (returned by
type(x)
)- some content You cannot change the identity.
You cannot change the type.
Some objects allow you to change their content (without changing the identity or the type, that is).
Some objects don’t allow you to change their content (more below).
The type is represented by a type object, which knows more about objects of this type (how many bytes of memory they usually occupy, what methods they have, etc).