我可以让相同值的不同变量指向不同的对象吗?

Can i make different variables of same values point to diffrent objects?

我认为这个问题在 SO 上可能已经有了答案,但我似乎找不到。如果您找到答案,请将其标记为重复。

我不是问为什么,但我怎么能不让它发生呢?

我希望 ji 有不同的 id

当我做的时候说,

>>> i = 6
>>> j = 6
>>> id(i) 
10919584
>>> id(j)
10919584 #I don't want this, I want j to point to a different object

所以,我明白了上面代码中发生的事情(或者至少我认为我明白了),但我的问题是如何防止它发生?

I am asking it just out of curiosity, it may or may not have any practical usage or relevance.

对此的可能用途有点奇怪;我找到的选项:

class NoFixedInt(int):
  pass

a = NoFixedInt(6)
b = NoFixedInt(6)
c = NoFixedInt(6)

print id(a)
# 4485155368
print id(b)
# 4485155656
print id(c)
# 4485155728

当然,我不知道这是否适合你,因为它有你必须投射所有东西的问题,但它确实有效。