>>> a = 12
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'a']
So it's everybody know!
But how we can get the value of a from dir()[-1]?
>>> a = 12
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'a']
So it's everybody know!
But how we can get the value of a from dir()[-1]?
you can use the exec
method.
a = 12
exec('b='+dir()[-1])
print(b)
>>> 12
the exec
method executes the string inputs.