小编Jas*_*Kim的帖子

Python3,如果两个变量具有相同的值,那么它们是否具有相同的地址?

在Python中,函数id()返回对象的内存地址。( https://docs.python.org/2/library/functions.html#id )\xe2\x80\xa8\xe2\x80\xa8 在 python 中,如果两个变量具有相同的值,那么它们是否具有相同的地址?\xe2\x80\xa8\xe2\x80\xa8

\n\n
In [30]: a = \'asdf\'\n\nIn [31]: hex(id(a))\nOut[31]: \'0x1082caa08\'\n\nIn [32]: b = \'asdf\'\n\nIn [33]: hex(id(b))\nOut[33]: \'0x1082caa08\'\n\nIn [34]: c = 2\n\nIn [35]: hex(id(c))\nOut[35]: \'0x1067295c0\'\n\nIn [36]: d = 2\n\nIn [37]: hex(id(d))\nOut[37]: \'0x1067295c0\' \n
Run Code Online (Sandbox Code Playgroud)\n

python

5
推荐指数
0
解决办法
522
查看次数

Django中的Queryset.create()方法,'self._for_write'是做什么用的?

下面这段代码中,代码的self._for_write含义是什么?

def create(self, **kwargs):
    """
    Create a new object with the given kwargs, saving it to the database
    and returning the created object.
    """
    obj = self.model(**kwargs)
    self._for_write = True
    obj.save(force_insert=True, using=self.db)
    return obj
Run Code Online (Sandbox Code Playgroud)

python django

5
推荐指数
1
解决办法
366
查看次数

标签 统计

python ×2

django ×1