[Python] 判斷是否為 空(None) (0 為 False)
Conditionals / Conditional expressions
a is None
/a is not None
a == None
/a != None
not a
(not 0
為True
)
Python 中視作 False 的物件
None
,False
0
()
,[]
,{}
,set()
,range(0)
In if/while statement
if a:
/if not a:
while a:
/while not a:
※ a 可以是變數,也可以是 list, dict, set, … 等 data structure
Last Updated on 2023/08/16 by A1go