布爾型True和False,not True為False,not False為True,以下是幾個常用的not的用法: (1) not與邏輯
判斷句if連用,代表not后面的表達式為False的時候,執行
冒號后面的語句。比如: a = False if not a: (這里因為a是False,所以not a就是True) print "hello" 這里就能夠輸出結果hello (2) 判斷元素是否在列表或者字典中,if a not in b,a是元素,b是列表或字典,這句話的意思是如果a不在列表b中,那么就執行
冒號后面的語句,比如: a = 5 b = [1, 2, 3] if a not in b: print "hello" 這里也能夠輸出結果hello