您如何知道变量是否已在运行时在代码中的特定位置设置?这并不总是显而易见的,因为(1)变量可以有条件地设置,(2)变量可以有条件地删除.我正在寻找像defined()Perl isset(),PHP或defined?Ruby中的东西.
if condition:
a = 42
# is "a" defined here?
if other_condition:
del a
# is "a" defined here?
Run Code Online (Sandbox Code Playgroud)