[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