Understanding memory location of Python variables

ip.bcrs at gmail.com ip.bcrs at gmail.com
Sat Jun 16 12:38:07 EDT 2018


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].



More information about the Python-list mailing list