On Mon, Jul 30, 2018 at 3:20 PM, Sunil Tech <sunil.tech...@gmail.com> wrote: > Python memory allocation is varying in all these use cases. Please help me > understand.
CPython is interning small integers and small strings as a form of optimisation. "The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object." For integers see https://docs.python.org/2/c-api/int.html for Python 2 or https://docs.python.org/3/c-api/long.html for Python 3. For strings see https://hg.python.org/cpython/file/3.5/Objects/codeobject.c#l51 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor