Why is it the same to view multiple methods id defined in a class in Python?

three methods, _ _ init__, name and add, are defined in the Myclass class, and the object is instantiated as C1. When you look at the id of the three methods, you find that they are the same. Why?
class Myclass (object):

def __init__(self, x):
    self.x = x

def name(self):
    print self.x

def add(self):
    self.x+"world"
    print self.x

 

C1 = Myclass ("hello")

print id (C1)
print id (c1.The initableness _)
print id (c1.name)
print id (c1.add)

output is
44030704
43882136

Mar.04,2021

this is because Python reuses the same memory address. After you point to id (c1.roomroominitarians _) , c1.roominitarians _ is no longer referenced and will be recycled, and then execute id (c1.name) when c1.name reuses the memory address that was just used c1.roominitableness _ , the following c1.add is the same.

there is a sentence in the introduction to the id () function in the Python document:

Two objects with non-overlapping lifetimes may have the same id () value

means that two objects whose lifecycles do not overlap are

that may have the same id.
Menu