The Data Structures and Algorithms written by Goodrich says that the python array is to store a group of related variables one after another in a continuous area of the computer memory, so the index can be accessed directly by calculating the address.For example,if the memory address of the first element of the array is 2146, and each element occupies two bytes of memory, then the memory address of the sixth element is 2146+2*5=2156, so the computer can directly access address 2156 to get the sixth elements.
But I tried to verify it,only to found that the results didn't accord with the theory.
str1 = "example"
for i in range(1,6):
print(id(str1[i])-id(str1[i-1]))
The output is as follows
-336384
471680
-492352
313664
178944
Why does this happen, if the memory address is not continuous, how does python get its memory address through index and then access the element?