[python]Python 中 if not 用法


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

 

需要注意的是'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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM