๐Ÿง Programming

1) ์˜ต์…”๋„ (Optional) (1) ๊ฐœ์š” Optional is primarily intended for use as a method return type where there is a clear need to represent "no result" and where using null is likely to cause errors. A variable whose type is Optional should never itself be null. it should always point to an Optional instance. ์œ„์˜ ๋‚ด์šฉ์€ JDK 8 API Document์— ์ฃผ์„์œผ๋กœ ์ ํ˜€์žˆ๋Š” ๋ถ€๋ถ„ ์ค‘ ์ผ๋ถ€๋ฅผ ๋ฐœ์ทŒํ•œ ๊ฒƒ์œผ๋กœ, ์˜์—ญํ•˜์ž๋ฉด Java Optional ํด๋ž˜์Šค๋Š” Java 8์—์„œ ์ถ”๊ฐ€๋œ ํด๋ž˜์Šค๋กœ ..
1) IntelliJ ์ธ์ฝ”๋”ฉ ์„ค์ • IntelliJ๋กœ ๊ฐœ๋ฐœํ•˜๋‹ค ๋ณด๋ฉด ๊ฐ€๋” ๊ฐ€๋‹ค ํ•œ๊ธ€์ด ๊นจ์ง€๋Š” ๊ฒฝ์šฐ๋ฅผ ์ข…์ข… ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋Ÿฐ ๊ฒฝ์šฐ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์ดˆ๊ธฐ์— ์ธ์ฝ”๋”ฉ ์„ค์ •์„ ๋จผ์ € ์ ์šฉํ•˜๊ณ  ๊ฐœ๋ฐœํ•˜๋„๋ก ํ•˜์ž! ๊ทธ๋Ÿฐ๋ฐ, ๋Œ€๋ถ€๋ถ„ UTF-8 ์ธ์ฝ”๋”ฉ์„ ์“ธํ…๋ฐ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ๋ชจ๋‘ UTF-8๋กœ ์„ค์ •ํ•ด์„œ ๋ฐฐํฌํ–ˆ์œผ๋ฉด ์ข‹์•˜์„ํ…๋ฐ ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ ๋‹ค. (1) IntelliJ VM Option ์„ค์ • IntelliJ๊ฐ€ ์„ค์น˜๋œ ๊ฒฝ๋กœ๋กœ ์ด๋™ํ•œ ๋‹ค์Œ, bin ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด์˜ "idea64.exe.vmoptions" ํŒŒ์ผ์„ ๋ฉ”๋ชจ์žฅ์œผ๋กœ ์‹คํ–‰ํ•œ๋‹ค. ์ฐธ๊ณ ๋กœ .vmoptions ํŒŒ์ผ์€ ๋‘ ๊ฐœ๊ฐ€ ์กด์žฌํ•  ์ˆ˜๋„ ์žˆ๋Š”๋ฐ ๋ณธ์ธ์ด ์‚ฌ์šฉ์ค‘์ธ OS์˜ bit์— ๋งž๋Š” ํŒŒ์ผ์„ ๋ฉ”๋ชจ์žฅ์œผ๋กœ ์—ด์ž! ๊ทธ ๋‹ค์Œ, ๋ฉ”๋ชจ์žฅ ๋งจ ์•„๋ž˜์— "-Dfile.encoding=UTF-8" ๋‚ด์šฉ์„ ์ถ”..
1) Python - Return๋ฌธ (1) and/or ์—ฐ์‚ฐ์ž ํ™œ์šฉ in Return Python์—์„œ๋Š” ์กฐ๊ฑด๋ฌธ์— ๋น„๊ต ์—ฐ์‚ฐ์‹ ๋Œ€์‹ ์— ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋…ํŠนํ•œ ๋ฌธ๋ฒ•์„ ์ œ๊ณตํ•˜๋Š”๋ฐ (์ด ๊ฒฝ์šฐ์—๋Š” ๋ณ€์ˆ˜ ์ž์ฒด๊ฐ€ ๋…ผ๋ฆฌ์‹์ด ๋œ๋‹ค) ๋งŒ์•ฝ ํ•จ์ˆ˜์˜ Return๋ฌธ์—์„œ ๋น„๊ต ์—ฐ์‚ฐ์‹ (and, or)๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, ๋ณ€์ˆ˜ ์ž์ฒด๋ฅผ ์กฐ๊ฑด์œผ๋กœ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ํ—ท๊ฐˆ๋ฆฌ๊ฒŒ ๋  ์—ฌ์ง€๊ฐ€ ๋งŽ๋‹ค. ์ˆซ์ž๋Š” 0์ด ์•„๋‹ˆ๋ฉด True, 0์ด๋ฉด False, ๋ฌธ์ž์—ด์€ ๋น„์–ด์žˆ์ง€ ์•Š์œผ๋ฉด True, ๋น„์–ด์žˆ์œผ๋ฉด False, ๊ทธ ์ด์™ธ์—๋„ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๋ฆฌ์ŠคํŠธ, ํŠœํ”Œ, ์…‹, ๋”•์…”๋„ˆ๋ฆฌ ๋“ฑ์˜ ๊ฐ์ฒด ๋˜ํ•œ ๋ฌธ์ž์—ด๊ณผ ๋น„์Šทํ•œ ๋งฅ๋ฝ์œผ๋กœ ๊ฐ์ฒด์˜ ๊ฐ’์ด ๋น„์–ด์žˆ์ง€ ์•Š์œผ๋ฉด True, ๋น„์–ด์žˆ์œผ๋ฉด False๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค. ๋‹ค๋งŒ, ์กฐ๊ฑด๋ฌธ์ด ์•„๋‹Œ Return๋ฌธ์—์„œ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด True๋‚˜ Fal..
1) ๋‚ด์žฅ ํ•จ์ˆ˜ (1) any(iterable) any() ํ•จ์ˆ˜๋Š” ์ˆœํšŒ ๊ฐ€๋Šฅํ•œ iterable ๊ฐ์ฒด๋ฅผ ์ธ์ž๋กœ ๋ฐ›์œผ๋ฉฐ, ์ „๋‹ฌ๋ฐ›์€ ๋ฐ์ดํ„ฐ ์ค‘ ์–ด๋Š ํ•˜๋‚˜๊ฐ€ True ๋ผ๋ฉด ํ•ญ์ƒ True๋กœ ์ถœ๋ ฅํ•œ๋‹ค. → ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์˜ OR ์—ฐ์‚ฐ์ž! (2) all(iterable) all() ํ•จ์ˆ˜๋Š” ์ˆœํšŒ ๊ฐ€๋Šฅํ•œ iterable ๊ฐ์ฒด๋ฅผ ์ธ์ž๋กœ ๋ฐ›์œผ๋ฉฐ, all() ํ•จ์ˆ˜๋Š” ์ „๋‹ฌ๋ฐ›์€ ๋ฐ์ดํ„ฐ ๋ชจ๋‘ True ์ธ ๊ฒฝ์šฐ, True๋กœ ์ถœ๋ ฅํ•œ๋‹ค. → ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์˜ AND ์—ฐ์‚ฐ์ž! (3) ์˜ˆ์ œ >>> any( [True, True, False, False, True] ) True >>> all( [True, True, False, False, True] ) False >>> any( [ [1,2], [], [3,1] ] ) True >>> all( [ ..
1) ๋‚ด์žฅ ํ•จ์ˆ˜ (1) zip (iterable, iterable, ...) zip() ํ•จ์ˆ˜๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ˆœํšŒ ๊ฐ€๋Šฅํ•œ iterable ๊ฐ์ฒด๋ฅผ ์ธ์ž๋กœ ๋ฐ›๊ณ , ๊ฐ ๊ฐ์ฒด๊ฐ€ ๋‹ด๊ณ  ์žˆ๋Š” ์›์†Œ๋ฅผ ํŠœํ”Œ์˜ ํ˜•ํƒœ๋กœ ์ฐจ๋ก€๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ˜๋ณต์ž (iterator)๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. [์˜ˆ์‹œ] numbers = [1, 2, 3] letters = [“A”, “B”, “C”] for pair in zip(numbers, letters): print(pair) [๊ฒฐ๊ณผ] >>> (1, 'A') >>> (2, 'B') >>> (3, 'C') → numbers, letters ๋ฆฌ์ŠคํŠธ์˜ ๊ฐ ์š”์†Œ๋ฅผ ๊บผ๋‚ด์–ด ํŠœํ”Œ์˜ ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜ [๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ] for number, upper, lower in zip("12345", "ABCDE", "abcde"..
1) ๋‚ด์žฅ ํ•จ์ˆ˜ (1) map(func, iterable) iterable ์š”์†Œ๋“ค์„ ํ•ด๋‹น ํ•จ์ˆ˜์— ์ ์šฉ์‹œ์ผœ Map ํ˜•ํƒœ๋กœ Return ํ•˜๊ธฐ ๋•Œ๋ฌธ์— list ํ˜น์€ tuple ์ž๋ฃŒํ˜•์œผ๋กœ ๋ณ€ํ™˜์‹œ์ผœ ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๋Œ€ํ‘œ์ ์œผ๋กœ iterable์—๋Š” ๋ฆฌ์ŠคํŠธ, ํŠœํ”Œ, ๋ฌธ์ž์—ด ๋“ฑ์ด ์‚ฌ์šฉ๋˜์–ด์ง„๋‹ค. ์ฆ‰, map() ํ•จ์ˆ˜๋Š” function์„ iterable์˜ ๋ชจ๋“  ์š”์†Œ์— ๋Œ€ํ•ด ์ ์šฉํ•˜๊ณ  function์— ์˜ํ•ด ๋ณ€๊ฒฝ๋œ iterator๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค [์˜ˆ์‹œ] L = [1,2] x, y = map(str, L) (2) filter(func, iterable) iterable ์š”์†Œ๋“ค์„ ํ•ด๋‹น ํ•จ์ˆ˜์— ์ ์šฉ์‹œ์ผœ filter ํ˜•ํƒœ๋กœ Return ํ•˜๊ธฐ ๋•Œ๋ฌธ์— list ํ˜น์€ tuple ์ž๋ฃŒํ˜•์œผ๋กœ ๋ณ€ํ™˜์‹œ์ผœ ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๋Œ€ํ‘œ์ ์œผ๋กœ iterable์—๋Š” ๋ฆฌ..
1) ํ•จ์ˆ˜ (Function) (1) ํ•จ์ˆ˜ ์„ ์–ธ def ํ•จ์ˆ˜๋ช…(์ธ์ž): ์ฒ˜๋ฆฌํ•  ๋ช…๋ น ์ฒ˜๋ฆฌํ•  ๋ช…๋ น ... return ... ํ•จ์ˆ˜ ์•ˆ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ(์ธ์ž)๋Š” ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ณ  ์—†์„ ์ˆ˜๋„ ์žˆ๋‹ค. [์ „๋‹ฌ๊ฐ’ ์œ ๋ฌด] return๋ฌธ์€ ํ•ด๋‹น ํ•จ์ˆ˜์—์„œ ๋ฆฌํ„ดํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฐ’์ด ์žˆ๋‹ค๋ฉด ์‚ฌ์šฉํ•˜๊ณ  ํŠน๋ณ„ํžˆ return ํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฐ’์ด ์—†๋‹ค๋ฉด ์ ์ง€ ์•Š๋Š”๋‹ค. [๋ฐ˜ํ™˜๊ฐ’ ์œ ๋ฌด] (2) ๋งค๊ฐœ๋ณ€์ˆ˜ ๊ธฐ๋ณธ๊ฐ’ def testFunc(name, age, lang=“python”): print(name, age, lang) testFunc(“joe”, 18) → ์ด์ฒ˜๋Ÿผ ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ, ํ•ด๋‹น ์ธ์ž๊ฐ’์„ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์•„๋„ ๊ธฐ๋ณธ๊ฐ’์ด ๋“ค์–ด๊ฐ€ ์žˆ์–ด → testFunc() ํ•จ์ˆ˜๊ฐ€ ์ž˜ ์ž‘๋™๋จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ๊ฒƒ์€ ํ•จ์ˆ˜ ์„ ์–ธ ์‹œ์— “testFunc(n..
1) ๊ธฐ์กด ๋ณตํ•ฉ๋ฌธ (if, for) # First Case numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] odd_numbers = [] for i in numbers: if numbers[i] % 2 == 0: odd_numbers.append(i) print(odd_numbers) # Second Case L = [1, 2, 3, 4, 5] for n in L: if n % 2 == 0: print(“odd”) else: print(“even”) 2) ํ•œ ์ค„ ๋ณตํ•ฉ๋ฌธ (if, for) # First Case L = [] [L.append(i) for i in range(10) if i % 2 == 0] print(L) # Second Case [print(“odd”) i..
Dev_sHu
'๐Ÿง Programming' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก