a = "hello"
b = "HEllo"
c = "hello"
d = b.lower()
print(d)
print(id(a))
print(id(b))
print(id(c))
print(id(d))
print((a is c))
print((a is d))
hello
1292474520552
1292504355816
1292504355984
True
False
d将b全转化为小写,这时就会重新分配一个内存去保存d;而a和c的值一样,占用一个内存。
a = "hello"
b = "HEllo"
c = "hello"
d = b.lower()
print(d)
print(id(a))
print(id(b))
print(id(c))
print(id(d))
print((a is c))
print((a is d))
hello
1292474520552
1292504355816
1292474520552
1292504355984
True
False
d将b全转化为小写,这时就会重新分配一个内存去保存d;而a和c的值一样,占用一个内存。