我正在学习python如何存储变量并用Python中的名称引用它,我遇到了一些我无法理解的东西。我为var1和var2分配了相同的值,并看到这些变量引用了同一个对象。我创建了另外两个名为var3和var4的变量,并赋予了相同的值(但与之前不同),我看到这些变量引用的对象并不相同。有人能解释一下这个区别吗?
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> vars()
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>}
>>> var1 = 100
>>> var2 = 100
>>> var1 is var2
True
>>> var3 = 500
>>> var4 = 500
>>> var3 is var4
False
>>> id (var1)
491903584
>>> id (var2)
491903584
>>> id (var3)
56573264
>>> id (var4)
87458544
>>>
>>> vars()
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'var1': 100, 'var2': 100, 'var3': 500, 'var4': 500}