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 equalit
In python you can define the __eq__
method to handle the ==
operator.
The is
operator checks if one object is the same as the other. (or more specifically two variables that reference one or two objects)
>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> a == b
True
>>> a is b
False
>>> c = a
>>> c is a
True
Now, this example uses the list
type, which you can think of as a class which defines an __eq__
method that compares equality of all its items.
Same for hash, you define a __hash__
method in your class that returns an integer that would identify your object. This is also available in the basic types that support hashing. See the hash
function.