[Python] Until what value does integer interning work in Python? [duplicate]

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

  1. Stack

    Stack Membro Participativo

    I was learning interning in Python and read that small values like -5 to 256 are already cached for easier access and would be interned. But after I ran it for bigger values like 1000 it was still returning True using the is operator. Why is that? If Python interns every integer then what is the difference between caching and interning?

    a=1000
    b=1000

    print(a is b)


    This returns True until when? If this is true all the time does that mean all the integers are interned in Python and if that's so what is the difference between caching and interning?

    Continue reading...

Compartilhe esta Página