简体   繁体   English

Python 中的整数变量是否在内存中保存指向 int 对象的指针?

[英]Do integer variables in Python hold pointers to int objects in memory?

I was reading an article that said everything is an object in Python.我在读一篇文章,说在 Python 中一切都是对象。

So I thought of researching how exactly integers in Python are stored internally, but unfortunately I got no good answer.所以我想研究 Python 中整数是如何在内部存储的,但不幸的是我没有得到好的答案。

My question is that do integer variables in Python hold pointers to integer objects in memory, or do they simply point to the integers, as is, in memory .我的问题是Python 中的整数变量是在内存中保存指向整数对象的指针,还是直接指向内存中的整数

Comparatively, how are integer variables stored in Java?相比之下,Java 中的整数变量是如何存储的? Are they also pointers to integer objects in memory or to integers, as is, in memory?它们是否也指向内存中的整数对象或指向内存中的整数?

From my understanding, in python, an int object is created, and then the variable holds a reference that points to this object.根据我的理解,在python中,创建了一个int对象,然后变量持有一个指向这个对象的引用。 Here is a little bit of reading you can do. 这里有一些你可以做的阅读。

In java, the integers are primitive types.在java中,整数是原始类型。 So the variables do not hold memory locations like reference types.所以变量不像引用类型那样保存内存位置。 Rather, they hold the value of the integer itself.相反,它们保存整数本身的值。 The wrappers for the primitive types are reference types.原始类型的包装器是引用类型。 Here is a good article for java 是一篇关于java的好文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM