ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • If
    python/기본 2022. 4. 29. 15:46
    x = 10
    
    if x < 0:
        print('negative')
    elif x == 0:
        print('zero')
    else:
        print('positive')
    
    x = 5
    y = 'even' if x % 2 == 0 else 'odd'
    print(y)  # odd
    
    ####################################################################
    a = 1
    b = 1
    
    c = a > 0 and b > 0
    print(c)  # True
    
    d = a > 0 or b > 0
    print(d)  # True
    
    x = 1
    y = [1, 2, 3]
    if x in y:
        print('in')
    
    if 100 not in y:
        print('not in')
    
    a = 1
    b = 2
    if not a == b:  # a != b
        print('Not equal')
    
    is_ok = True
    if not is_ok:
        print("not ok")
    
    ####################################################################
    #  0, 0.0, '', [], {}, set() 을 모두 False 로 판정한다.
    #  empty string, empty list 판정에 사용할 수 있다.
    is_ok = ''
    if is_ok:
        print('OK')
    else:
        print('No')  # is_ok 가 empty string 이면 False 로 판정
    
    is_empty = None
    print(type(is_empty))  # <class 'NoneType'>
    
    if is_empty is not None:
        print('None !!!')
    
    print(1 == True)  # True
    print(1 is True)  # False

    'python > 기본' 카테고리의 다른 글

    Input  (0) 2022.04.29
    While  (0) 2022.04.29
    Set  (0) 2022.04.29
    Dictionary  (0) 2022.04.29
    Tuple  (0) 2022.04.29

    댓글

Designed by Tistory.