Variable Name Value Address
import _ctypes as ct
a,b=3,4
print(a,b)
p1,p2=id(a),id(b)
print(p1,p2)
print(ct.PyObj_FromPtr(p1),ct.PyObj_FromPtr(p2))
a,b=3,4
variables =dir()
print("Dir ",variables)
for variable in variables:
print(variable)
globalvariables=globals()
print("Global Variables")
for variable in globalvariables:
print(variable)
def f():
print("Local Variables")
la=2
lb=3
localvariables=locals()
for variable in localvariables:
print(variable)
f()
Program Sample
import IPython as ip
a,b=1,2
variables=vars()
print(variables)
print(type(variables))
print(variables.keys())
print(variables.values())
variables.pop("a")
print(variables.keys())
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x000000CFCB62C160>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'C:/Users/Champak Roy/PycharmProjects/pythonProject3/chapter 2.py', '__cached__': None, 'ip': <module 'IPython' from 'H:\\Anaconda3\\lib\\site-packages\\IPython\\__init__.py'>, 'a': 1, 'b': 2, 'variables': {...}}
<class 'dict'>
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', '__file__', '__cached__', 'ip', 'a', 'b', 'variables'])
dict_values(['__main__', None, None, <_frozen_importlib_external.SourceFileLoader object at 0x000000CFCB62C160>, None, {}, <module 'builtins' (built-in)>, 'C:/Users/Champak Roy/PycharmProjects/pythonProject3/chapter 2.py', None, <module 'IPython' from 'H:\\Anaconda3\\lib\\site-packages\\IPython\\__init__.py'>, 1, 2, {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x000000CFCB62C160>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'C:/Users/Champak Roy/PycharmProjects/pythonProject3/chapter 2.py', '__cached__': None, 'ip': <module 'IPython' from 'H:\\Anaconda3\\lib\\site-packages\\IPython\\__init__.py'>, 'a': 1, 'b': 2, 'variables': {...}}])
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', '__file__', '__cached__', 'ip', 'b', 'variables'])
0 Comments