ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Set
    python/기본 2022. 4. 29. 15:17
    a = {1, 2, 3, 2, 3, 4, 4, 5}
    print(a)  # {1, 2, 3, 4, 5}
    print(type(a))  # <class 'set'>
    
    b = {2, 3, 7}
    c = a - b
    print(c)  # {1, 4, 5}
    
    print(a)  # {1, 2, 3, 4, 5}
    print(b)  # {2, 3, 7}
    
    c = a & b
    print(c)  # {2, 3} 교집합
    
    c = a | b
    print(c)  # {1, 2, 3, 4, 5, 7} 합집합
    
    c = a ^ b
    print(c)  # {1, 4, 5, 7} 대칭 차집합
    
    ####################################################################
    s = {1, 2, 3, 4, 5}
    s.add(6)
    print(s)  # {1, 2, 3, 4, 5, 6}
    s.remove(6)
    print(s)  # {1, 2, 3, 4, 5}
    
    l = [1, 2, 2]
    x = set(l)
    print(x)  # {1, 2}

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

    While  (0) 2022.04.29
    If  (0) 2022.04.29
    Dictionary  (0) 2022.04.29
    Tuple  (0) 2022.04.29
    List  (0) 2022.04.29

    댓글

Designed by Tistory.