class A:
def self_method(self):
pass
@staticmethod
def static_method():
pass
a1, a2 = A(), A()
print(a1.self_method == a2.self_method,
id(a1.self_method) == id(a2.self_method),
a1.self_method is a2.self_method)
print(a1.static_method == a2.static_method,
id(a1.static_method) == id(a2.static_method),
a1.static_method is a2.static_method)
输出:
(False, True, False) (True, True, True)
为什么id(a1.self_method) == id(a2.self_method)
是True
,而a1.self_method is a2.self_method
是False
?这是什么意思? python是否为每个对象都重新创建此方法?