在python 判断语句中 None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于 False
not None == not False == not '' == not 0 == not [] == not {} == not ()

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

需要注意的是'0'这个进行判断返回的是true

def test(val):
    if not val:
        print 'not'
    else:
        print 'yes'

test(0)
test(None)

test('0')


if not 0:
    print 1111

返回

not
not
yes
1111

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄