๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

IT96

[Python] ์ดํ„ฐ๋ ˆ์ดํ„ฐ(Iterator)_ํ”„๋กœ๊ทธ๋žจ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์„ธ๊ณ„๋ฅผ ํƒ๊ตฌํ•ฉ์‹œ๋‹ค. ํŒŒ์ด์ฌ์—์„œ ๋ฐ˜๋ณต ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด(ํด๋ž˜์Šค)๋ฅผ ํ‘œํ˜„ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค ์ดํ„ฐ๋ ˆ์ดํ„ฐ๋Š” iter()ํ•จ์ˆ˜์™€ next()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐ˜๋ณต(Inerator)์„ ์ˆ˜ํ–‰ ### ํด๋ž˜์Šค ์ •์˜ํ•˜๊ธฐ class MyIterator : ### ํด๋ž˜์Šค ์ƒ์„ฑ์ž ์ •์˜ํ•˜๊ธฐ def __init__(self) : self.current_value = 0 print(f"#1(__init__) : self = {self} / self.current_value={self.current_value}") ### ์ž์‹ ์˜ ํด๋ž˜์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” iter ํ•จ์ˆ˜ ์ •์˜ def __iter__(self) : print(f"#2(__iter__) : self = {self}") return self ### ๋ฐ˜๋ณต์„ ์ˆ˜ํ–‰ํ•˜๋Š” next .. 2023. 11. 17.
[Python] 2. ๋„์„œ ์ž…๊ณ /๋Œ€์ถœ/๋ฐ˜๋‚ฉ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ํ‚ค์˜ค์Šคํฌ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ์‹ค์Šต (decorator ์ด์šฉ) ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์„ธ๊ณ„๋ฅผ ํƒ๊ตฌํ•ฉ์‹œ๋‹ค. * class ์‚ฌ์šฉํ•œ ์‹ค์Šต์€ ์•„๋ž˜ ๊ฒŒ์‹œ๊ธ€ ์ฐธ๊ณ  ๋ฐ”๋ž๋‹ˆ๋‹ค. 2023.11.14 - [IT/Python] - [Python] ๋„์„œ ์ž…๊ณ /๋Œ€์ถœ/๋ฐ˜๋‚ฉ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ํ‚ค์˜ค์Šคํฌ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋žจ ์‹ค์Šต (class ์ด์šฉ) [Python] ๋„์„œ ์ž…๊ณ /๋Œ€์ถœ/๋ฐ˜๋‚ฉ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ํ‚ค์˜ค์Šคํฌ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋žจ ์‹ค์Šต (class ์ด์šฉ) ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์„ธ๊ณ„๋ฅผ ํƒ๊ตฌํ•ฉ์‹œ๋‹ค. ๋„์„œ ์ž…๊ณ /๋Œ€์ถœ/๋ฐ˜๋‚ฉ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ํ‚ค์˜ค์Šคํฌ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋žจ ์‹ค์Šต [๋ฏธ์…˜] ๋„์„œ๋ชฉ๋ก : ์ƒˆ๋กœ์šด ์ฑ…์ด ๋„์„œ๊ด€์— [์ž…๊ณ ]๋˜์—ˆ์„ ๋•Œ ํ”„๋กœ๊ทธ๋žจ ์ž‘์„ฑ ๋„์„œ๋Œ€์ถœ : ๋„์„œ ๋ชฉ๋ก ityranno.tistory.com * ํšŒ์›๊ฐ€์ž… ๊ธฐ๋Šฅ ์ถ”๊ฐ€ํ•œ ์‹ค์Šต์€ ์•„๋ž˜ ๊ฒŒ์‹œ๊ธ€ ์ฐธ๊ณ  ๋ฐ”๋ž๋‹ˆ๋‹ค. 2023.11.20 - [IT/Python] - [Python] 3. ๋„์„œ ์ž…๊ณ /๋Œ€์ถœ.. 2023. 11. 16.
[Python] ํด๋กœ์ €(Closure) ํ”„๋กœ๊ทธ๋žจ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์„ธ๊ณ„๋ฅผ ํƒ๊ตฌํ•ฉ์‹œ๋‹ค. - ํ•จ์ˆ˜ ์•ˆ์— ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹ - ํ•จ์ˆ˜ ์•ˆ์— ์žˆ๋Š” ํ•จ์ˆ˜๋Š” ๋ฐ”๊นฅ์ชฝ ํ•จ์ˆ˜์—์„œ ์ฐธ์กฐํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค. - ํ•จ์ˆ˜ ์•ˆ์— ํ•จ์ˆ˜๋Š” ์‚ฌ์šฉ์ด ๋๋‚˜๋ฉด ๋ฉ”๋ชจ๋ฆฌ์—์„œ ํ•ด์ œ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค. ํด๋กœ์ € ํ•จ์ˆ˜ ์ •์˜ํ•˜๊ธฐ ### ํด๋กœ์ € ํ•จ์ˆ˜ ์ •์˜ํ•˜๊ธฐ def outer_function(x) : print(f"#1 : x = {x}") ### ๋‚ด๋ถ€ ํ•จ์ˆ˜ ์ •์˜ : ์‹ค์ œ ์‹คํ–‰๋˜๋Š” ํ•จ์ˆ˜ def inner_function(y) : print(f"#2 : y = {y}") s = x + y print(f"#3 : s = {s}") return s print("#4 -------") return inner_function ํด๋กœ์ € ํ•จ์ˆ˜ ํ˜ธ์ถœํ•˜๊ธฐ ### ํด๋กœ์ € ํ•จ์ˆ˜ ํ˜ธ์ถœํ•˜๊ธฐ.. 2023. 11. 14.
[Python] ์œ ๋‹ˆ์ฝ”๋“œ ํ”„๋กœ๊ทธ๋žจ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์„ธ๊ณ„๋ฅผ ํƒ๊ตฌํ•ฉ์‹œ๋‹ค. - ์œ ๋‹ˆ์ฝ”๋“œ(Unicode)๋Š” ์ „ ์„ธ๊ณ„์˜ ๋ชจ๋“  ๋ฌธ์ž๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ํ‘œ์ค€ ์ธ์ฝ”๋”ฉ ์ฒด๊ณ„ - ์œ ๋‹ˆ์ฝ”๋“œ ํ”„๋กœ๊ทธ๋žจ : ์–ธ์–ด, ๋ฌธ์ž, ํŠน์ˆ˜๊ธฐํ˜ธ ๋“ฑ์˜ ํ‘œ์ค€ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉํ•˜๊ธฐ ### ๋ฌธ์ž์—ด ๊ฒฐํ•ฉํ•˜๊ธฐ string1 = "ํŒŒ์ด์ฌ(python)" string2 = "์žฌ๋ฏธ์žˆ์–ด์š”" string3 = "!!!" print(string1 + string2 + string3) ๋ฌธ์ž์—ด์„ UTF-8๋กœ ์ธ์ฝ”๋”ฉํ•˜๊ธฐ ### ๋ฌธ์ž์—ด์„ UTF-8๋กœ ์ธ์ฝ”๋”ฉํ•˜๊ธฐ text = "์•ˆ๋…•ํ•˜์„ธ์š”" encode_text = text.encode("utf-8") encode_text ๋ฌธ์ž์—ด์„ UTF-8๋กœ ๋””์ฝ”๋”ฉํ•˜๊ธฐ ### ๋ฌธ์ž์—ด์„ UTF-8๋กœ ๋””์ฝ”๋”ฉํ•˜๊ธฐ decode_text = encode_text.decode("utf-8") d.. 2023. 11. 14.

loading