id(变量名)
此函数可以获取到变量所指向的数据的内存地址
name=["zhangwuji","zhaomin","yideng","yangguo","zhaomin","zhaomin","zhangwuji","1","1","1","1"]
print(id(name))
print(id(name[0]))
print(id(name[1]))
print(id(name[2]))
print(id(name[3]))
print(id(name[4]))
print(id(name[5]))
print(id(name[6]))
"""
11198056
11168208
11454016
11454048
11454080
11454016
11454016
11168208
"""
对于存储数字来说:
>>> name = [1,2,3,4,5,6,7,8]
>>> print(id(name[0]))
1548613552
>>> print(id(name[1]))
1548613568
>>> print(id(name[2]))
1548613584
>>> print(id(name[3]))
1548613600
>>> print(id(name[4]))
1548613616
>>> print(id(name[5]))
1548613632
>>> print(id(name[6]))
1548613648
>>> print(id(name[7]))
1548613664
>>> print(id(name[1]) - id(name[0]))
16 # 相减后可以发现,占用2字节
>>> print(id(name[2]) - id(name[1]))
16 # 相减后可以发现,占用2字节
>>> print(id(name[3]) - id(name[2]))
16 # 相减后可以发现,占用2字节
>>> print(id(name[4]) - id(name[2]))
32 # 相减后可以发现,占用4字节
>>>