在以下情况下:
test = False
test = ""
test = 0
test = 0.0
test = []
test = ()
test = {}
test = set()
该if
测试将有所不同:
if test: #False
if test is not None: #True
之所以如此,是因为is
测试身份,含义
test is not None
相当于
id(test) == id(None) #False
因此
(test is not None) is (id(test) != id(None)) #True