python nonetype怎么判斷

小億
217
2024-01-11 08:11:02
欄目: 編程語言

在Python中,可以使用type()函數(shù)來判斷一個(gè)變量的類型。如果變量是None類型,即NoneTypetype()函數(shù)將返回NoneType。例如:

x = None

if type(x) == type(None):
    print("x is NoneType")
else:
    print("x is not NoneType")

輸出結(jié)果為:

x is NoneType

0