. , , , , (, ).
: id
>>> n1 = N()
>>> n2 = N()
>>> id(n1) == id(n2)
False
, Python , . , , ! , , :
>>> n1 = N()
>>> n2 = n1
>>> id(n1) == id(n2)
True
: --?
, Python . , :
, . , . ? ?
:
CPython id (!) . . builtin_id bltinmodule.c, 907.
Python, __init__ __del__:
class N:
def __init__(self):
print "Creating", id(self)
def __del__(self):
print "Destroying", id(self)
>>> id(N())
Creating 4300023352
Destroying 4300023352
4300023352
, Python , . Python , , , , , . :
>>> id(N()), id(N()), id(N())
Creating 4300023352
Destroying 4300023352
Creating 4300023352
Destroying 4300023352
Creating 4300023352
Destroying 4300023352
(4300023352, 4300023352, 4300023352)
: ""
, "", ( ). , ββ Python ? , N?
, , N object.
, , , , , .
, Python. obmalloc.c , . .
...
? . , , Python , : 4- , , .
Python : , -. , N , , , , . , :
id(N())
Python P ( A).
Python P.
- , . , P, A.
id(N()).
Python P . A ( O), B.
O, , A P.
, . , id(N()),id(N()), , .
, . , , , .
: ?
. pythonrun.c, :
, "". ( ); ( ). , .