示例一:
v1 = [11,22,33]
v2 = [11,22,33] v1 = 666
v2 = 666v1 = "asdf"
v2 = "asdf"#以上数据都不是同一个内存地址# 按理 v1 和 v2 应该是不同的内存地址。特殊:
1. 整型: -5 ~ 256
2. 字符串:"alex",'asfasd asdf asdf d_asdf ' ----"f_*" * 3 - 重新开辟内存。
示例二:
v1 = [11,22,33,44]
v1 = [11,22,33]
示例三:
v1 = [11,22,33]
v2 = v1 #同一个内存地址# 练习1 (内部修改)
v1 = [11,22,33]
v2 = v1
v1.append(666)
print(v2) # 含 666# 练习2:(赋值)
v1 = [11,22,33]
v2 = v1
v1 = [1,2,3,4]
print(v2)# 指向V1原有内存地址:[11,22,33]# 练习3:(重新赋值)
v1 = 'alex'
v2 = v1
v1 = 'oldboy'
print(v2) # alex
示例四
v = [1,2,3]
values = [11,22,v]# 练习1:
"""
v.append(9)
print(values) # [11,22,[1,2,3,9]]
"""
# 练习2:
"""
values[2].append(999) # values[2] 指向 v地址
print(v) # [1, 2, 3, 999]
"""
# 练习3:
"""
v = 999
print(values) # [11, 22, [1, 2, 3]]
"""
# 练习4:
values[2] = 666
print(v) # [1, 2, 3]
示例五
v1 = [1,2]
v2 = [2,3]v3 = [11,22,v1,v2,v1] #v1、v2 表示V1的内存地址#通过V3找到V1内存进行修改,V1里面的值也会进行修改,
#如果修改V1中的值,V3指向V1的值,也会进行修改,如下图所示