If not / is None 차이

epiphany·2022년 10월 7일

개념 정리

목록 보기
1/2
post-thumbnail

항상 If is None / If is not None 만 확인했었는데 If / If not이라는 개념이 있다는 걸 이제 알았다..😂
If / If not 너무 유용

If not

None뿐만 아니라 빈값으로 생각되는 경우, False의 경우는 모두 If not에 들어감

  • "", False, None, 0, [], {}

If is None

오직 None인 경우에만 해당됨

  • None


📑 Test Code

A = ""  # 1, 4
A = True  # 2, 4
A = False  # 1, 4
A = None  # 1, 3
A = 0  # 1, 4
A = '0'  # 2, 4
A = []  # 1, 4
A = {}  # 1, 4
A = 2
 
# 1
if not A:  # "", False, None, 0, [], {}
    print("if not A")
# 2
if A:  # True, '0'
    print("if A")
# 3
if A is None:  # Only None
    print("if A is None")
# 4
if A is not None:  # None이 아닌 모든 경우
    print("if A is not None")
profile
iamda.tistory.com 이사 중

0개의 댓글