-2
a = 10 # range -5 to 256
b = 10 # range -5 to 256
print(id(a))
print(id(b))
print(a is b)

# OK THAT'S FINE 

a = 10 # range -5 to 256
b = 10 # range -5 to 256
print(id(a))
print(id(b)) # same memory adress
print(a is b)

# That's working

c = 3 # range -5 to 256
d = 5 # range -5 to 256
print(id(c))
print(id(d)) 
print(c is d) 

不同的内存地址 O_o False 因为... meeeehhh 范围应该没问题!

4

1 回答 1

1

通过下图,您应该明白为什么:

  • a is b是真的
  • c is d是假的

对于 -5 到 256 之间的数字

为什么:

  • e is f是假的

对于此特殊范围之外的其他数字

在此处输入图像描述

于 2022-02-16T20:53:59.200 回答