for start, let's define a class and instance of the class
class c:
@classmethod
def m(cls, a):
return a + 1
a = c()
those methods are used the same way
>>> c.m(5), a.m(5)
6, 6
and cls
in both cases is c
but c.m is a.m
is False
and c.m == a.m
is True
why is the class method called by instance and class not the same and why am I able to call it even by an instance of that class
it would make sense if cls
were not the same in both cases
EDIT:
I already knew the difference between is
and ==
I was already successfully using is
to check if two classes are the same
(type(a) is int
for example), but I did learn I should use it for is None
, so thanks anyway for leading me to that page
My question actually was why are they not the same object
they even have same ID id(a.m) == id(c.m)