[python]Python 中 if not 用法

前端之家收集整理的这篇文章主要介绍了[python]Python 中 if not 用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

 

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

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

test(0)
test(None)

test(0)


 0:
    print 1111

返回

not
not
yes
1111

 

猜你在找的Python相关文章