The Extra getrefcount Reference
import sys
x = [1, 2, 3]
y = x
print(sys.getrefcount(x))
del y
print(sys.getrefcount(x))
sys.getrefcount() is a CPython-specific function that reports one more than you might expect, because passing x into the call itself creates one extra, temporary reference for the duration of the call. With x and y both bound, the first print shows 3: one for x, one for y, one for that temporary argument reference. After del y removes one binding, what exact number does the second print show, under CPython 3.14?
Sign in to answer questions and track your progress
Sign In