I'm currently trying to learn python from the book of Mark Lutz. In one of the chapters, he talks about typing and about shared links. He writes that some objects are pre-cached, so that frequent numbers and strings are not created for the sake of optimization. I don’t understand this, when calling the sys.getrefcount (0) function, my pyCharm environment gives 173 response and I understand in principle what this means, but if you pass a different value, like 1234127832.11101, then the response from the function will be equal to 3. I do not understand where exactly this number comes from, because it should be like 1, since this object is used once. Please help!

    1 answer 1

    One reference for the constant, one reference for the argument passed to getrefcount and another one created by the compiler in the process.

    • Thank you. And where can I read deeper about this topic? - Sergey Patient
    • I'm not sure that there is any centralized source on the internal Python device, except for CPython sources. Is that this unfinished book and scattered throughout the internet articles. For example, in this blog there are many clever publications about CPython intestines. - Sergey Gornostaev