Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类声明语句是否会导致python中的内存分配? 我知道在C++语言中,直到实例化内存才分配。 在python中也是这样吗? 我正在读这门课。在这门课程中,为了详细阐述这个片段,给出了一个奇怪的数字: class Point: """ Point class for representing and manipulating x,y coordinates. """ def __init__(self): """ Create a new point at the origin """ self.x = 0 self.y = 0 p = Point() # Instantiate an object of type Point q = Point() # and make a second point print("Nothing seems to have happened with the points")_Python_Class - Fatal编程技术网

类声明语句是否会导致python中的内存分配? 我知道在C++语言中,直到实例化内存才分配。 在python中也是这样吗? 我正在读这门课。在这门课程中,为了详细阐述这个片段,给出了一个奇怪的数字: class Point: """ Point class for representing and manipulating x,y coordinates. """ def __init__(self): """ Create a new point at the origin """ self.x = 0 self.y = 0 p = Point() # Instantiate an object of type Point q = Point() # and make a second point print("Nothing seems to have happened with the points")

类声明语句是否会导致python中的内存分配? 我知道在C++语言中,直到实例化内存才分配。 在python中也是这样吗? 我正在读这门课。在这门课程中,为了详细阐述这个片段,给出了一个奇怪的数字: class Point: """ Point class for representing and manipulating x,y coordinates. """ def __init__(self): """ Create a new point at the origin """ self.x = 0 self.y = 0 p = Point() # Instantiate an object of type Point q = Point() # and make a second point print("Nothing seems to have happened with the points"),python,class,Python,Class,这一数字如下: 我从图中得到的是,在执行通过声明类的行之后,分配了一些内存(在到达实例化部分之前)!。但这一行为并未明确提及。 我说得对吗?是这样吗?Python中的所有内容都是对象,包括类、函数和模块。class、def和import语句都是可执行语句,主要用于较低级别的API。就类而言,它们实际上是类型类的实例,如下所示: class Foo(object): def __init__(self): self.bar = 42 这只是一个快捷方式: def __i

这一数字如下:

我从图中得到的是,在执行通过声明类的行之后,分配了一些内存(在到达实例化部分之前)!。但这一行为并未明确提及。
我说得对吗?是这样吗?

Python中的所有内容都是对象,包括类、函数和模块。
class
def
import
语句都是可执行语句,主要用于较低级别的API。就类而言,它们实际上是
类型
类的实例,如下所示:

class Foo(object):
    def __init__(self):
        self.bar = 42
这只是一个快捷方式:

def __init__(self):
    self.bar = 42

Foo = type("Foo", [object], {"__init__": __init__}) 

del __init__ # clean up the current namespace

正如您所看到的,此时确实发生了实例化。

因为类本身是一个对象,并且在运行时声明,所以您确实需要一些内存来保存类本身@德塞兹。请发布一个关于这个主题的更多细节和参考的答案,这样我就可以被标记为答案了。谢谢。如果您能提供一些链接和资源,我将不胜感激。