Not sure what you are asking, so clearly what is happening ...
>>> x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x = 10
>>> 'x' in vars()
True
>>> vars()['x']
10
>>> del x
>>> 'x' in vars()
False
>>> x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
, Python locals() ( vars() - dir(obj), )... , , , . , . C, NULL.
>>> x = 10
>>> def func():
... global x
... del x
...
>>> x
10
>>> func()
>>> x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>>
:
, , (: , , - ) , 0. IMO he python, .
ID, :
Help on built-in function id in module __builtin__:
id(...)
id(object) -> integer
Return the identity of an object. This is guaranteed to be unique among
simultaneously existing objects. (Hint: it the object memory address.)
, , , ( python , , - ruby, ).
>>> import sys
>>> x = 10
>>> sys.getrefcount(x)
26
>>> id(x)
140266396760096
>>> y = x
>>> id(y) == id(x)
True
>>> z = 10
>>> id(z) == id(y) == id(x)
True
>>> sys.getrefcount(y)
28
>>> sys.getrefcount(z)
28
>>> del y, z
>>> sys.getrefcount(x)
26
>>> del x
>>> x = 'charlie'
>>> id(x)
4442795056
>>> y = 'charlie'
>>> z = x
>>> id(x) == id(y) == id(z)
True
>>> sys.getrefcount(x)
4
>>> sys.getrefcount(y)
4
>>> sys.getrefcount(z)
4
>>> del y
>>> del x
>>> sys.getrefcount(z)
2
>>> id(z)
4442795056
>>> del z
>>>
>>> id('charlie')
4442795104
'x' == 10, . 10 , , - . python, , . 24 10. x = 10 25- , sys.getrefcount(x) - 26- ( ). y = 10 z = x, , , . del , 3 , 10 .
x = 'charlie', y = 'charlie' , , z = x. , . 'charlie'. , id('charlie'), , , , .
- 'charlie' 10 . 10 , . , . 'charlie' , 10 .
>>> hex(id(10))
'0x7f9250c0b820'
>>> hex(id('charlie'))
'0x108cfac60