Why does refs increment 2 for every new object in Python?

It’s a little strange for me that the number of refs in an interactive environment increases by 2 after defining a new object. I only created one object, right?

>>> v Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'v' is not defined [41830 refs] >>> v = "v" [41832 refs] 
+6
python cpython python-internals
source share
1 answer

Your job worked by creating an entry in the globals() dictionary, where v as the key and "v" as the value. These two links (one for the key and one for the value), although in this case they probably both refer to the same string "v" .

+8
source share

All Articles