๋ฐ์ํ
set : ์งํฉ
- ์์๊ฐ ์ค๋ณต๋์ง ์๋๋ค. (์ค๋ณต ์ ๊ฑฐ)
- ์์์ ์์๋ ๋ณด์ฅ๋์ง ์๋๋ค.
arr1 = [1,2,3]
# ์งํฉ์ผ๋ก ์์ฑ => {1,2,3}
s = set(arr1)
# ์์ ์ถ๊ฐ => {1,2,3,4}
s.add(4)
# ์์ ์ ๊ฑฐ => {1,2,3}
s.remove(4) # ์์๊ฐ ์์ผ๋ฉด ์๋ฌ ๋ฐ์
s.discard(4) #์์๊ฐ ์์ด๋ ์๋ฌ ๋ฐ์ X
s1 = {1,2,3}
s2 = {2,4,6}
# ํฉ์งํฉ => {1,2,3,4,6}
print(s1 | s2)
# ๊ต์งํฉ => {2}
print(s1 & s2)
# ์ฐจ์งํฉ => {1,3}
print(s1 - s2)
๋ฐ์ํ
'๐Language > โ Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] math ๋ผ์ด๋ธ๋ฌ๋ฆฌ (1) | 2024.12.09 |
---|---|
[Python] ๋์ ๋๋ฆฌ (1) | 2024.12.09 |
[Python] list (1) | 2024.09.12 |
[Python] ์ ์ (0) | 2024.09.11 |
[Python] ๋ฌธ์์ด (0) | 2024.09.11 |