Pythonの「None」は、Javaで言うnull、C言語で言うNULLに相当し、通常の変数のように==で判定しません。
Python None判定「is None」
def check_is_none(lst):
if lst is None:
print("lst [is None]")
else:
print("lst Not [is None]")
lst = None
check_is_none(lst)
# lst [is None]
lst = []
check_is_none(lst)
# lst Not [is None]
Python None判定「is not None」
def check_is_not_none(lst):
if lst is not None:
print("lst [is not None]")
else:
print("lst Not [is not None]")
lst = None
check_is_not_none(lst)
# lst Not [is not None]
lst = []
check_is_not_none(lst)
# lst [is not None]
コメント