[Python] Why does Python keep a reference count on False and True?

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I was looking at the source code to the hasattr built-in function and noticed a couple of lines that piqued my interest:

    Py_INCREF(Py_False);
    return Py_False;

    ...

    Py_INCREF(Py_True);
    return Py_True;


    Aren't Py_False and Py_True global values? Just out of sheer curiosity, why is Python keeping a reference count for these variables?

    Continue reading...

Compartilhe esta Página