在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\nIn [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 下面这段代码中,代码的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)