I am encountering a weird situation.
I want to check if my variables x
, y
, z
exist.
To do that, I tried:
>>> [var in locals() for var in ["x", "y", "z"]]
[False, False, False]
Then, I assign x
, y
, z
to some values:
>>> x, y, z = 1, 2, 3
Nevertheless, I still have:
>>> [var in locals() for var in ["x", "y", "z"]]
[False, False, False]
But x, y, z exist one by one:
>>> for var in ["x", "y", "z"]:
... print(var in locals())
...
True
True
True
Does someone have an explanation?