๐ฑ ์๋ฃํ ๋ณ ๋ฉ์๋
์๊พธ ๊น๋จน์ด์ ์ฌ์ฉํ ๋ ๋ง๋ค ๋ณด๋ ค๊ณ ์ฌ๋ ค๋ด ๋๋ค. ๐๐
๐ list
๊ฐ๋ณ(mutable) ์ํ์ค์ด๋ฏ๋ก ์์์ ์ถ๊ฐ, ์ญ์ , ์ ๋ ฌ ๋ฑ ๋ค์ํ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
| ๋ฉ์๋ | ์ค๋ช |
|---|---|
list.append(x) |
๋ฆฌ์คํธ์ ๋์ x๋ฅผ ์ถ๊ฐํฉ๋๋ค. |
list.extend(iterable) |
๋ค๋ฅธ iterable์ ๋ชจ๋ ์์๋ฅผ ๋ฆฌ์คํธ์ ๋ง๋ถ์ ๋๋ค. |
list.insert(i, x) |
์ธ๋ฑ์ค i ์์น์ x๋ฅผ ์ฝ์
ํฉ๋๋ค. |
list.remove(x) |
๋ฆฌ์คํธ์์ ์ฒซ ๋ฒ์งธ๋ก ๋ฑ์ฅํ๋ x๋ฅผ ์ญ์ ํฉ๋๋ค. ์์ผ๋ฉด ValueError ๋ฐ์. |
list.pop([i]) |
์ธ๋ฑ์ค i์ ์์๋ฅผ ๋ฐํํ๊ณ ์ญ์ ํฉ๋๋ค. ๊ธฐ๋ณธ๊ฐ์ ๋ง์ง๋ง ์์์
๋๋ค. |
list.clear() |
๋ฆฌ์คํธ์ ๋ชจ๋ ์์๋ฅผ ์ญ์ ํฉ๋๋ค. |
list.index(x[, start[, end]]) |
์ฒซ ๋ฒ์งธ๋ก ๋ฑ์ฅํ๋ x์ ์ธ๋ฑ์ค๋ฅผ ๋ฐํํฉ๋๋ค. ๊ตฌ๊ฐ์ ์ง์ ํ ์ ์์ต๋๋ค. |
list.count(x) |
๋ฆฌ์คํธ์์ x๊ฐ ๋ฑ์ฅํ ํ์๋ฅผ ๋ฐํํฉ๋๋ค. |
list.sort(key=None, reverse=False) |
๋ฆฌ์คํธ๋ฅผ ์ ์๋ฆฌ์์ ์ ๋ ฌํฉ๋๋ค. (์ ๋ฆฌ์คํธ ๋ฐํ X) key ํจ์์ reverse ์ต์
์ง์. |
list.reverse() |
๋ฆฌ์คํธ์ ์์๋ฅผ ์ ์๋ฆฌ์์ ๋ค์ง์ต๋๋ค. |
list.copy() |
๋ฆฌ์คํธ์ ์์ ๋ณต์ฌ๋ณธ์ ๋ฐํํฉ๋๋ค. |
๐ tuple
๋ถ๋ณ(immutable) ์ํ์ค์ด๋ฏ๋ก ๋ฉ์๋๊ฐ ์ ํ์ ์ ๋๋ค.
| ๋ฉ์๋ | ์ค๋ช |
|---|---|
tuple.count(x) |
x๊ฐ ๋ฑ์ฅํ ํ์๋ฅผ ๋ฐํํฉ๋๋ค. |
tuple.index(x[, start[, end]]) |
์ฒซ ๋ฒ์งธ๋ก ๋ฑ์ฅํ๋ x์ ์ธ๋ฑ์ค๋ฅผ ๋ฐํํฉ๋๋ค. |
๐๏ธ set
์งํฉ ์ฐ์ฐ์ ์ง์ํ๋ ๊ฐ๋ณ ์๋ฃํ์ ๋๋ค.
| ๋ฉ์๋ | ์ค๋ช |
|---|---|
set.add(x) |
์งํฉ์ x๋ฅผ ์ถ๊ฐํฉ๋๋ค. ์ด๋ฏธ ์์ผ๋ฉด ๋ฌด์๋ฉ๋๋ค. |
set.remove(x) |
์งํฉ์์ x๋ฅผ ์ ๊ฑฐํฉ๋๋ค. ์์ผ๋ฉด KeyError ๋ฐ์. |
set.discard(x) |
์งํฉ์์ x๋ฅผ ์ ๊ฑฐํฉ๋๋ค. ์์ผ๋ฉด ๋ฌด์๋ฉ๋๋ค. |
set.pop() |
์งํฉ์์ ์์์ ์์๋ฅผ ๋ฐํํ๊ณ ์ ๊ฑฐํฉ๋๋ค. |
set.clear() |
๋ชจ๋ ์์๋ฅผ ์ ๊ฑฐํฉ๋๋ค. |
set.copy() |
์งํฉ์ ์์ ๋ณต์ฌ๋ณธ์ ๋ฐํํฉ๋๋ค. |
set.update(*others) |
๋ค๋ฅธ ์งํฉ/iterable์ ๋ชจ๋ ์์๋ฅผ ์ถ๊ฐํฉ๋๋ค. |
set.union(*others) |
ํฉ์งํฉ์ ๋ฐํํฉ๋๋ค. (์ฐ์ฐ์: ` |
set.intersection(*others) |
๊ต์งํฉ์ ๋ฐํํฉ๋๋ค. (์ฐ์ฐ์: &) |
set.difference(*others) |
์ฐจ์งํฉ์ ๋ฐํํฉ๋๋ค. (์ฐ์ฐ์: -) |
set.symmetric_difference(other) |
๋์นญ์ฐจ์งํฉ์ ๋ฐํํฉ๋๋ค. (์ฐ์ฐ์: ^) |
set.issubset(other) |
๋ถ๋ถ์งํฉ์ธ์ง ๊ฒ์ฌํฉ๋๋ค. (์ฐ์ฐ์: <=) |
set.issuperset(other) |
์์์งํฉ์ธ์ง ๊ฒ์ฌํฉ๋๋ค. (์ฐ์ฐ์: >=) |
set.isdisjoint(other) |
๊ต์งํฉ์ด ์๋์ง ๊ฒ์ฌํฉ๋๋ค. |
๐ dict
ํค-๊ฐ ๋งคํ์ ์ง์ํ๋ ์๋ฃํ์ ๋๋ค.
| ๋ฉ์๋ | ์ค๋ช |
|---|---|
dict.get(key[, default]) |
key๊ฐ ์กด์ฌํ๋ฉด ๊ฐ์, ์์ผ๋ฉด default๋ฅผ ๋ฐํํฉ๋๋ค. ๊ธฐ๋ณธ์ None. |
dict.keys() |
๋ชจ๋ ํค๋ฅผ ๋ณด์ฌ์ฃผ๋ view ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค. |
dict.values() |
๋ชจ๋ ๊ฐ์ ๋ณด์ฌ์ฃผ๋ view ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค. |
dict.items() |
๋ชจ๋ (ํค, ๊ฐ) ์์ ๋ณด์ฌ์ฃผ๋ view ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค. |
dict.pop(key[, default]) |
key๋ฅผ ์ ๊ฑฐํ๊ณ ํด๋น ๊ฐ์ ๋ฐํํฉ๋๋ค. ์์ผ๋ฉด default ์ฌ์ฉ, ์์ผ๋ฉด KeyError. |
dict.popitem() |
๋ง์ง๋ง์ผ๋ก ์ฝ์ ๋ (ํค, ๊ฐ) ์์ ์ ๊ฑฐํ๊ณ ๋ฐํํฉ๋๋ค. |
dict.clear() |
๋ชจ๋ ํญ๋ชฉ์ ์ญ์ ํฉ๋๋ค. |
dict.update([other]) |
๋ค๋ฅธ dict๋ key-value ์์ผ๋ก ๊ฐฑ์ ํฉ๋๋ค. |
dict.copy() |
์์ ๋ณต์ฌ๋ณธ์ ๋ฐํํฉ๋๋ค. |
dict.setdefault(key[, default]) |
key๊ฐ ์์ผ๋ฉด ๊ฐ์ ๋ฐํ, ์์ผ๋ฉด default ๊ฐ์ ๋ฃ๊ณ ๋ฐํํฉ๋๋ค. |
dict.fromkeys(iterable[, value]) |
iterable์ ์์๋ฅผ ํค๋ก ํ์ฌ ์ dict๋ฅผ ์์ฑํฉ๋๋ค. (ํด๋์ค ๋ฉ์๋) |
'Programming > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ํ์ด์ฌ ์ปฌ๋ ์ ํ์ ๋ณํ (0) | 2025.10.04 |
|---|---|
| ํ์ด์ฌ ํ์ผ ์ฝ๊ธฐโข์ฐ๊ธฐ (0) | 2025.10.03 |
| ํ์ด์ฌ ์ปฌ๋ ์ ์๋ฃํ (0) | 2025.09.27 |
| ํ์ด์ฌ ๊ธฐ์ด๋ฌธ๋ฒ3 (๋ฐ๋ณต๋ฌธ) (0) | 2025.09.27 |
| ํ์ด์ฌ ๊ธฐ์ด๋ฌธ๋ฒ2 (์กฐ๊ฑด๋ฌธ) (0) | 2025.09.26 |