Understanding memory location of Python variables
Joel Goldstick
joel.goldstick at gmail.com
Sat Jun 16 13:19:04 EDT 2018
On Sat, Jun 16, 2018 at 12:38 PM, <ip.bcrs at gmail.com> wrote:
> Hi everyone,
>
> I'm intrigued by the output of the following code, which was totally contrary to my expectations. Can someone tell me what is happening?
>
>>>> myName = "Kevin"
>>>> id(myName)
> 47406848
>>>> id(myName[0])
> 36308576
>>>> id(myName[1])
> 2476000
>
> I expected myName[0] to be located at the same memory location as the myName variable itself. I also expected myName[1] to be located immediately after myName[0].
> --
> https://mail.python.org/mailman/listinfo/python-list
Others can probably give a more complete explanation, but small
numbers, and apparently letters are cached since they are so common.
--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
More information about the Python-list
mailing list