如何知道运行时代码中的特定位置是否已设置变量?这并不总是显而易见的,因为 (1) 可以有条件地设置变量,并且 (2) 可以有条件地删除变量。我正在寻找类似的东西defined()
在 Perl 或isset()
在 PHP 中或defined?
在红宝石中。
if condition:
a = 42
# is "a" defined here?
if other_condition:
del a
# is "a" defined here?
try:
thevariable
except NameError:
print("well, it WASN'T defined after all!")
else:
print("sure, it was defined.")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)