我可以用吗:
if A:
Run Code Online (Sandbox Code Playgroud)
代替
if A is not None:
Run Code Online (Sandbox Code Playgroud)
后者似乎很冗长.有区别吗?
我不确定这是一个自以为是的问题,还是我误解了“隐式”和“显式”在 Python 上下文中的真正含义。
a = []
# my understanding is that this is implicit
if not a:
print("list is empty")
# my understanding is that this is explicit
if len(a) == 0:
print("list is empty")
Run Code Online (Sandbox Code Playgroud)
我正在尝试遵循 Python 规则的禅宗,但我很想知道这是否适用于这种情况,还是我想多了?感谢我能得到的任何指导。