Lees de code zorgvuldig
# Deterministic refcount tracker β mirrors CPython behaviour but
# without sys.getrefcount's baseline-by-1 quirk. Every Python
# binding increments; every del / list-removal decrements.
class Refcount:
def __init__(self, name):
self.name = name
self.count = 1 # the original binding
def bind(self): # `y = x`
self.count += 1
def unbind(self): # `del y`
self.count -= 1
def append_to(self, container_name):
self.count += 1
def container_dropped(self, n):
self.count -= n
obj = Refcount("payload") # 1 β the original assignment
y = obj; obj.bind() # rebind β 2
print(obj.count)
obj.unbind() # del y β 1
print(obj.count)
big_list = ["item"]
big_list.append(obj); obj.append_to("big_list") # +1 β 2
big_list.append(obj); obj.append_to("big_list") # +1 β 3
print(obj.count)
obj.container_dropped(2) # del big_list β list had 2 refs to obj
print(obj.count)
# What does this print? Type your prediction.Wat zal het programma uitprinten? Schrijf hier: