I am also wondering about this behavior. Thank you Chris A for providing the explanation.
On Jun 16, 2018, at 5:45 PM, Chris Angelico <[email protected]<mailto:[email protected]>> wrote: On Sun, Jun 17, 2018 at 2:38 AM, <[email protected]<mailto:[email protected]>> 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]. A string or array in C is allocated in contiguous memory. Python, however, is not C. What you're looking at is the identities of objects, not the memory locations of bytes. Everything you're assuming about C should be discarded. ChrisA -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
