Python是否有类似空字符串变量的地方,你可以这样做:
if myString == string.empty:
Run Code Online (Sandbox Code Playgroud)
无论如何,检查空字符串值的最优雅方法是什么?我""每次都发现硬编码检查空字符串不太好.
val = ""
del val
if val is None:
print("null")
Run Code Online (Sandbox Code Playgroud)
我跑了上面的代码,但得到了NameError: name 'val' is not defined.
如何判断变量是否为null,并避免NameError?