-
νμ΄μ¬ | #11 set λ©μλ λ€λ£¨κΈ°μΉ΄ν κ³ λ¦¬ μμ 2023. 10. 29. 23:56
Set λ©μλ
pop()
μμ΄ν μ μμ ν λ μ¬μ©νμ§λ§, κ°μ λλ€μΌλ‘ μμ νλ€.
=> μ΄λ€ κ°μ΄ μμ λ μ§ λͺ¨λ₯Έλ€.
fruits = {"apple", "banana", "cherry"} x = fruits.pop() print(fruits); #{apple, "cherry"} print(x); #banana
clear()
clear λ©μλλ set μμ λΉμμ€λ€. λͺ¨λ κ°μ μμ ν΄μ£Όλ λ©μλλ€.
fruits = {"apple", "banana", "cherry"} fruits.clear() print(fruits); #set()
del
del ν€μλλ set μ체λ₯Ό μμ νλ€.
fruits = {"apple", "banana", "cherry"} del fruits print(fruits); #NameError: name 'fruits' is not defined
union()
union λ©μλλ λ κ°μ setμ μλ‘μ΄ setμμ λͺ¨μμ£Όλ μν μ νλ€.
fruits = {"apple", "banana", "cherry"} addFruits = {"watermelon", "kiwi"} newFruits = fruits.union(addFruits) print(newFruits) #{'cherry', 'kiwi', 'banana', 'apple', 'watermelon'}
update()
update λ©μλλ unionμ²λΌ μλ‘μ΄ setμ λͺ¨μμ£Όλ κ² μλ, μλ μλ set κ³Ό ν©μ³μ€λ€.
fruits = {"apple", "banana", "cherry"} addFruits = {"watermelon", "kiwi"} fruits.update(addFruits) print(fruits)