python 基本语法-内存存储

字符串可以相加,相乘

name = "smx"

new_name=name*2

print(new_name)

namename

输入input 接收的内容是字符串

内存相关内容

v1 = [11,22,33]
v2 = [11,22,33]
V1和v2是不同的地址空间
v1 = [11,22,33]
v1=[11,12]

v1 = [11,22,33]
v2=v1
v2指向同一地址
v1.append(666)
print(v2) 含666


v1 = [11, 22, 33] 内存是一个地址
v2 = v1 v2指向V1的地址
v1 = [1, 2, 3] 新建一个地址
print(v2)
[11,22,33]

v1 = 'smx'
v2 = v1
v1 = 'abc'
print(v2)
smx
列表和字典可以内部修改,赋值重新开辟一块空间
v1 = [1, 2, 3]
v2 = [11, 22, v1]
v1.append(9)
print(v2)
****
[11, 22, [1, 2, 3, 9]]

v1 = [1, 2, 3]
v2 = [11, 22, v1]
v2[2].append(9)
print(v1)
[1, 2, 3, 9]
v1 = [1, 2, 3]
v2 = [11, 22, v1]
v1 = 999
print(v2)
[11, 22, [1, 2, 3]]

v1 = [1, 2, 3]
v2 = [11, 22, v1]
v2[2] = 9
print(v1)
[1, 2, 3]
查看变量的内存地址
v1 = [1, 2, 3]
v2 = v1
v1.append(9)
print(id(v1), id(v2))


v1 = [1, 2, 3]
v2 = v1
v1.append(9)
print(id(v1), id(v2))
v1 = 99
print(id(v1), id(v2))

1538997772872 1538997772872
140730184146816 1538997772872

-5---256,字符串,整形,浮点型

小数据池,缓存 数字是一个地址

==比较值

is内存地址是否相等

 








猜你喜欢

转载自www.cnblogs.com/smxwxh/p/11185160.html
0条评论
添加一条新回复