aa = []
bb = [1] bc
print(not aa, not b) # True False d
cc = [] d
dd = None ccde
f
print(cc is None, dd is None) # False True (可以看到在判空列表时这样写是容易出错的)
print(not cc, not dd) # True True
ee = True eef
ff = False f
print(ee is None, ff is None) # Falshe False
print(not ee, not ff) # False True
hh = ()
print(hh is None, not hh) # False True
总结:
1、判断列表建议用not x,用x is None 会有问题!
2、判断None对象,则 not x 与 x is None是一样的效果!