🐍 Python

hizikang01Β·2025λ…„ 4μ›” 23일

python

λͺ©λ‘ 보기
1/2

핡심 ν•¨μˆ˜

ν•¨μˆ˜λͺ…μ„€λͺ…μ˜ˆμ‹œ
print()μ½˜μ†”μ— 좜λ ₯
input()μ‚¬μš©μž μž…λ ₯ λ°›κΈ°
len()길이 λ°˜ν™˜
range()반볡 κ°€λŠ₯ν•œ 숫자 λ²”μœ„ 생성
list()리슀트둜 λ³€ν™˜
map()각 μš”μ†Œμ— ν•¨μˆ˜ 적용list(map(int, ["1", "2"])) β†’ [1, 2]
filter()쑰건을 λ§Œμ‘±ν•˜λŠ” κ°’λ§Œ 필터링list(filter(lambda x: x>0, [-1,2,3])) β†’ [2,3]
zip()μ—¬λŸ¬ iterable 병렬 λ¬ΆκΈ°list(zip([1,2], ['a','b'])) β†’ [(1,'a'),(2,'b')]
enumerate()μΈλ±μŠ€μ™€ 값을 νŠœν”Œλ‘œ λ°˜ν™˜list(enumerate(['a','b'])) β†’ [(0,'a'),(1,'b')]
max()μ΅œλŒ“κ°’ λ°˜ν™˜
min()μ΅œμ†Ÿκ°’ λ°˜ν™˜
sum()합계 λ°˜ν™˜
sorted()μ •λ ¬λœ 리슀트 λ°˜ν™˜
abs()μ ˆλŒ“κ°’ λ°˜ν™˜
int()μ •μˆ˜ν˜•μœΌλ‘œ λ³€ν™˜
str()λ¬Έμžμ—΄λ‘œ λ³€ν™˜
float()μ‹€μˆ˜ν˜•μœΌλ‘œ λ³€ν™˜
bool()λΆˆλ¦¬μ–Έκ°’ λ³€ν™˜
ord()문자λ₯Ό μ•„μŠ€ν‚€μ½”λ“œλ‘œ λ³€ν™˜ord('A') β†’ 65
chr()μ•„μŠ€ν‚€μ½”λ“œλ₯Ό 문자둜 λ³€ν™˜chr(65) β†’ 'A'
divmod()(λͺ«, λ‚˜λ¨Έμ§€) νŠœν”Œ λ°˜ν™˜divmod(7, 3) β†’ (2, 1)
pow()κ±°λ“­μ œκ³± 계산pow(2, 3) β†’ 8
round()반올림round(3.1415, 2) β†’ 3.14
set()μ§‘ν•© 생성set([1,2,2,3]) β†’ {1,2,3}
dict()λ”•μ…”λ„ˆλ¦¬ 생성dict(a=1, b=2) β†’ {'a':1, 'b':2}
tuple()νŠœν”Œ 생성tuple([1,2,3]) β†’ (1,2,3)
type()객체 νƒ€μž… λ°˜ν™˜
isinstance()클래슀 μΈμŠ€ν„΄μŠ€ μ—¬λΆ€ 확인

보쑰 ν•¨μˆ˜

ν•¨μˆ˜λͺ…μ„€λͺ…μ˜ˆμ‹œ
all()λͺ¨λ‘ 참이면 Trueall([1,2,3]) β†’ True
any()ν•˜λ‚˜λΌλ„ 참이면 Trueany([0, 0, 1]) β†’ True
bin()2μ§„μˆ˜ λ¬Έμžμ—΄ λ°˜ν™˜bin(7) β†’ '0b111'
oct()8μ§„μˆ˜ λ¬Έμžμ—΄ λ°˜ν™˜oct(8) β†’ '0o10'
hex()16μ§„μˆ˜ λ¬Έμžμ—΄ λ°˜ν™˜hex(15) β†’ '0xf'
eval()λ¬Έμžμ—΄μ„ μ½”λ“œλ‘œ μ‹€ν–‰eval("1+2") β†’ 3
reversed()μ—­μˆœ 반볡자 λ°˜ν™˜list(reversed([1,2,3])) β†’ [3,2,1]
id()객체 고유 ID λ°˜ν™˜null
globals() / locals()심볼 ν…Œμ΄λΈ” λ°˜ν™˜null
dir()객체의 속성과 λ©”μ„œλ“œ 리슀트null
getattr()객체의 속성 λ°˜ν™˜null
setattr()객체에 속성 μ„€μ •null
hasattr()속성 쑴재 μ—¬λΆ€ 확인null
delattr()속성 μ‚­μ œnull
super()λΆ€λͺ¨ 클래슀 μ°Έμ‘°null
staticmethod() / classmethod()정적/클래슀 λ©”μ„œλ“œ μ •μ˜null

ν•¨μˆ˜λ³„ μ£Όμš” μ‚¬μš© μœ ν˜•

μœ ν˜•μžμ£Ό μ‚¬μš©ν•˜λŠ” ν•¨μˆ˜
μ •λ ¬/μš°μ„ μˆœμœ„sorted, max, min
리슀트/λ°°μ—΄ μ‘°μž‘map, filter, zip, enumerate, list, set, tuple
λ¬Έμžμ—΄ 문제ord, chr, str, int, float
쑰건 검사all, any, bool, isinstance
μˆ˜ν•™ μ—°μ‚°abs, pow, divmod, round, sum
ν•΄μ‹œ/λ”•μ…”λ„ˆλ¦¬dict, in, getattr, setattr, hasattr

λ‚΄μž₯ λͺ¨λ“ˆ/ν•¨μˆ˜

λͺ¨λ“ˆμ£Όμš” κΈ°λŠ₯μ˜ˆμ‹œ
heapqμ΅œμ†Œ/μ΅œλŒ€ νž™ κ΅¬ν˜„heapq.heappush() / heapq.heappop()
collectionsμœ μš©ν•œ μ»¨ν…Œμ΄λ„ˆ 클래슀Counter, defaultdict, deque
itertoolsμˆœμ—΄/μ‘°ν•© λ“± 반볡자 생성permutations, combinations, product
bisect이진 탐색 기반 μ‚½μž…/검색bisect.bisect_left(), bisect.insort()

0개의 λŒ“κΈ€