class s:
a = 0
def obj(self):
pass
@classmethod
def cla(cls):
pass
@staticmethod
def sta():
pass
t = s()
print(t.a is s.a)
print(t.obj is s.obj)
print(t.cla is s.cla)
print(t.sta is s.sta)
print(id(t.a), id(s.a))
print(id(t.obj), id(s.obj))
print(id(t.cla), id(s.cla))
print(id(t.sta), id(s.sta))
print(id(t.a) == id(s.a))
print(id(t.obj) == id(s.obj))
print(id(t.cla) == id(s.cla))
print(id(t.sta) == id(s.sta))
In the above program, cla() is a classmethod. classmethod are created once in the class, not its object. while checking whether the address of the classmethod in class and its object are same or not. I found some strange thing.
When I see the address of the classmethod of both class and its object, they printed the same address.
print(id(t.cla), id(s.cla)) # both printed address are same 1944310966664 1944310966664
once again I check that with equal to operator on id's of both class method. it printed True.
print(id(t.cla) == id(s.cla)) # it print true
but when I try this with is operator, that print false.
print(t.cla is s.cla) # it print false
I really don't know why this happen. the is operator also check whether the both the id's are same or not. Please anyone help me in this.
Advance thanks for investing your time to clear my doubt.