Python入門 値が入っていない判定をするテクニック、Noneを判定する場合
# 値が入っていない判定をするテクニック
# is_ok = True
# False, 0, 0.0, '', [], (), set()
is_ok = [1, 2, 3, 4]
if is_ok:
print('OK!')
else:
print('NO!')
# Noneを判定する場合
is_empty = None #print (help(is_empty))
# a = None かどうかを判定するときは == ではなく is を使う
"""
if is_empty == None:
print('None!!!')
"""
if is_empty is None:
print('None!!!')
print(1 == True) # True
print(1 is True) # False
print(None is None) # True
この記事が気に入ったらサポートをしてみませんか?