-1

I have a problem with understanding this code.

I called dd 3 times, but why is it not deleting the previous stack of the function each time?

I am getting this output:

11
12
13

Could you explain a solution? Also, where else could this problem occur?

class Hello():
    v=10

class K():
    a=Hello()
    def p(self):
        self.a.v=self.a.v+1
        print(self.a.v)
        self.a=None
def dd(): 
    ff=K()
    ff.p()
    del(ff)
dd()
dd()
dd()
iz_
  • 15,923
  • 3
  • 25
  • 40

1 Answers1

0

When you delete ff, you are deleting a new object that inherited properties from K (which inherited properties from Hello()).

When properties are inherited to an object, they change together, but do not get deleted together. You will need to reinitialize the properties to get them to change back.

Daniel Scott
  • 979
  • 7
  • 16