有关于None

None 表示空 不同于 空字符串 空的列表 0 False

类型不同,值不同

print(type(None)) <class 'NoneType'>None是None类
a=''
b=False
c=[]
print(a==None)  #False
print(b==None) #False
print(c==None) #False  #值不相等

深入

def fun():
    return None

a = fun()
if not a:
    print('S')
else:
    print('F')

if a is None:
    print('S')
else:
    print('F')
#S
#S

类中默认非空

类中为空的情况

由bool决定True or False,与len无关 (即print 只有 bool call True,或者bool call False ))

Last updated

Was this helpful?