๐Ÿ—ฃ๏ธ/Python 3

[Python] ์˜ˆ์™ธ์ฒ˜๋ฆฌ

1. ์˜ค๋ฅ˜ ์ข…๋ฅ˜์— ์ƒ๊ด€์—†์ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด except ๋ธ”๋ก ์ˆ˜ํ–‰ try: ... except: ... 2. ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๋ฏธ๋ฆฌ ์ •ํ•ด ๋†“์€ ์˜ค๋ฅ˜ ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•  ๋•Œ๋งŒ except ๋ธ”๋ก ์ˆ˜ํ–‰ try: ... except ๋ฐœ์ƒ์˜ค๋ฅ˜: ... 3. ๋ฏธ๋ฆฌ ์ •ํ•ด ๋†“์€ ์˜ค๋ฅ˜ ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•  ๋•Œ๋งŒ except ๋ธ”๋ก ์ˆ˜ํ–‰ + ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€์˜ ๋‚ด์šฉ์„ ์•Œ๊ณ  ์‹ถ์„ ๋•Œ try: ... except ๋ฐœ์ƒ ์˜ค๋ฅ˜ as ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€ ๋ณ€์ˆ˜: ... * try...finally -> finally์ ˆ์€ try๋ฌธ ์ˆ˜ํ–‰ ๋„์ค‘ ์˜ˆ์™ธ ๋ฐœ์ƒ ์—ฌ๋ถ€์— ์ƒ๊ด€ ์—†์ด ํ•ญ์ƒ ์ˆ˜ํ–‰๋จ. * raise -> ์˜ค๋ฅ˜ ๊ฐ•์ œ๋กœ ๋ฐœ์ƒ์‹œํ‚ด. * Exception ํด๋ž˜์Šค ์ƒ์† -> ์˜ˆ์™ธ ๋งŒ๋“ฆ.

[Python] ํด๋ž˜์Šค

ํด๋ž˜์Šค์™€ ๊ฐ์ฒด - ํด๋ž˜์Šค๋กœ ๋งŒ๋“  ๊ฐ์ฒด๋Š” ๊ฐ์ฒด๋งˆ๋‹ค ๊ณ ์œ ํ•œ ์„ฑ๊ฒฉ์„ ๊ฐ€์ง. - ๋™์ผํ•œ ํด๋ž˜์Šค๋กœ ๋งŒ๋“  ๊ฐ์ฒด๋“ค์€ ์„œ๋กœ ์ „ํ˜€ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค. # ์˜ˆ์‹œ) ์‚ฌ์น™์—ฐ์‚ฐ ํด๋ž˜์Šค class FourCal: def setdata(self, first, second): self.first = first self.second = second def add(self): result = self.first + self.second return result def sub(self): result = self.first - self.second return result def mul(self): result = self.first * self.second return result def div(self): result = self...

[Python] ์ž๋ฃŒํ˜•(๋ฌธ์ž์—ด, ๋ฆฌ์ŠคํŠธ, ํŠœํ”Œ, ๋”•์…”๋„ˆ๋ฆฌ, ์ง‘ํ•ฉ, lambda) / ํŒŒ์ผ ์ฝ๊ณ  ์“ฐ๊ธฐ

๋ช‡ ๋‹ฌ ๋™์•ˆ ์ฝ”๋”ฉ์ด๋ž‘ ๋‹ด ์Œ“๊ณ  ์‚ด์•˜๋”๋‹ˆ ๊ทธ์ƒˆ ํŒŒ์ด์ฌ ๋ฌธ๋ฒ• ์กฐ๊ธˆ์”ฉ ํ—ท๊ฐˆ๋ฆฌ๊ธฐ ์‹œ์ž‘..^^ ๊ทธ๋ž˜์„œ ๊ธฐ๋ณธ๋งŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ฆฌํ•˜๋ ค๊ณ  ํ•จ. - count (๋ฌธ์ž ๊ฐœ์ˆ˜ ์„ธ๊ธฐ) - find, index (์œ„์น˜ ์•Œ๋ ค์ฃผ๊ธฐ) - join (๋ฌธ์ž์—ด ์‚ฝ์ž…) - upper (์†Œ๋ฌธ์ž->๋Œ€๋ฌธ์ž), lower (๋Œ€๋ฌธ์ž->์†Œ๋ฌธ์ž) - strip, lstrip, rstrip (๊ณต๋ฐฑ ์ง€์šฐ๊ธฐ) - replace (๋ฌธ์ž์—ด ๋ฐ”๊พธ๊ธฐ) - split (๋ฌธ์ž์—ด ๋‚˜๋ˆ„๊ธฐ) ๋ฆฌ์ŠคํŠธ๋ช… = [ ์š”์†Œ1, ์š”์†Œ2, ์š”์†Œ3, ... ] - len - append (๋งจ ๋งˆ์ง€๋ง‰์— ์ถ”๊ฐ€) / insert(a,b) (a๋ฒˆ์งธ ์œ„์น˜์— b๋ฅผ ์‚ฝ์ž…) - del a[x] / remove / pop - sort - reverse - index - count - extend(x) (a ..