SlideShare a Scribd company logo
1 of 38
Download to read offline
About
About
About
What we will cover
What we will cover
What we will cover
Ch1 Pythonic Thinking : How we write a โ€œclean codeโ€
Item 2: Follow the PEP 8 Style Guide
Python Enhancement Proposal #8
a wealth of details about how to
write clear Python code.
updated as the Python language
evolves.
http://www.python.org/dev/peps/pep-0008/
Item 2: Follow the PEP 8 Style Guide
https://www.slideshare.net/japh44/type-annotations-in-python-whats-whys-and-wows
Item 2: Follow the PEP 8 Style Guide
https://www.slideshare.net/japh44/type-annotations-in-python-whats-whys-and-wows
Item 2: Follow the PEP 8 Style Guide
Item 2: Follow the PEP 8 Style Guide
Item 2: OOP
Item 2: OOP
ํด๋ž˜์Šค(class) ๋ฉ”์„œ๋“œ
โ€“ ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋”ฐ๋ผ์„œ ๊ฐ์ฒด์˜ ์ƒ์„ฑ ์—†์ด๋„
์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. (๊ฐ์ฒด์™€ ๋ฌด๊ด€ํ•˜๋ฏ€๋กœ self๊ฐ€ ์—†์Œ์— ์œ ์˜)
โ€“ ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์—์„œ ๊ฐ์ฒด์˜ ์†์„ฑ์„ ์ ‘๊ทผํ•˜๊ฑฐ๋‚˜ ์‚ฌ์šฉํ•˜๋ ค๋Š” ํ–‰์œ„๋Š” ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.
(๊ฐ์ฒด์™€ ๊ด€๋ จ์ด ์—†๋‹ค)
โ€“ cls ๋ผ๋Š” ํด๋ž˜์Šค๋ฅผ ์˜๋ฏธํ•˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌ๋ฐ›์•„, ํด๋ž˜์Šค ๋ณ€์ˆ˜ ๋“ฑ์„ ์•ก์„ธ์Šค ํ•  ์ˆ˜ ์žˆ
๋‹ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋กœ๋Š” ํด๋ž˜์Šค ์ž์‹ ์ด ์ž๋™์œผ๋กœ ์ „๋‹ฌ๋˜๊ณ  ์ด ์ธ์ˆ˜๋ฅผ 'cls'๋ผ๊ณ  ํ•œ๋‹ค
โ€“ ๋ฉ”์„œ๋“œ ์•ž์— @classmethod ๋ผ๋Š” Decorator๋ฅผ ํ‘œ์‹œ
์ธ์Šคํ„ด์Šค(Instance) ๋ฉ”์„œ๋“œ
โ€“ ๊ฐ์ฒด(์ธ์Šคํ„ด์Šค)๋ฅผ ํ†ตํ•ด์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์„œ๋“œ
โ€“ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ ์ดํ›„์— ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ ์ฃผ๋กœ ๊ฐ์ฒด์˜ ์†์„ฑ์„ ์กฐ์ž‘, ๊ด€๋ฆฌ ๋ฐ ์ •๋ณด์˜ ์ƒ
์„ฑ์— ์ด์šฉ๋œ๋‹ค.
โ€“ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜์— ์—‘์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฉ”์„œ๋“œ์˜ ์ฒซ๋ฒˆ์งธ ํŒŒ๋ผ๋ฏธํ„ฐ์— ํ•ญ์ƒ ๊ฐ์ฒด ์ž์‹ ์„
์˜๋ฏธํ•˜๋Š” "self"๋ผ๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ–๋Š”๋‹ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ ์ธ์ž self๋กœ ์ธ์Šคํ„ด์Šค ์ž์‹ ์ด ์ž๋™
์œผ๋กœ ํ˜ธ์ถœ๋œ๋‹ค.
Item 2: OOP
Item 2: OOP
Item 2: OOP
์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜: ํด๋ž˜์Šค ์ •์˜์—์„œ ๋ฉ”
์„œ๋“œ ์•ˆ์—์„œ ์‚ฌ์šฉ๋˜๋ฉด์„œ
"self.๋ณ€์ˆ˜๋ช…"์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋˜๋ฉฐ,
์ด๋Š” ๊ฐ ๊ฐ์ฒด ๋ณ„๋กœ ์„œ๋กœ ๋‹ค๋ฅธ ๊ฐ’์„
๊ฐ–๋Š” ๋ณ€์ˆ˜์ด๋‹ค.
ํด๋ž˜์Šค ๋ณ€์ˆ˜๊ฐ€ ํ•˜๋‚˜์˜ ํด๋ž˜์Šค์—
ํ•˜๋‚˜๋งŒ ์กด์žฌํ•˜๋Š” ๋ฐ˜๋ฉด,
์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋Š”
๊ฐ ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค๋งˆ๋‹ค
๋ณ„๋„๋กœ ์กด์žฌํ•œ๋‹ค.
Item 2: OOP
self๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐ์ฒด ์ž์‹ ์ด ๊ฐ€์ง„ ์†์„ฑ์„
๋ณ€ํ™”์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ์ฒด์˜ ์†์„ฑ ๊ฐ’์ด
์ •ํ™•ํ•˜๊ฒŒ ๊ด€๋ฆฌ๋œ๋‹ค.
Item 2: OOP
โ€ข์บก์Šํ™”(encapsulation)๋Š” ๊ฐ์ฒด์˜ ์™ธ๋ถ€์—์„œ ๊ฐ
์ฒด ๋‚ด๋ถ€์˜ ์†์„ฑ์„ ์ง์ ‘์ ์œผ๋กœ ์ ‘๊ทผ, ์†์„ฑ์„ ์ฝ๊ฑฐ
๋‚˜ ๋ณ€๊ฒฝ์‹œํ‚ค์ง€ ๋ชปํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค.
โ€ข๊ฐ์ฒด์˜ ์†์„ฑ์„ ์ ‘๊ทผ, ์†์„ฑ์„ ์ฝ๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•˜๊ณ 
์‹ถ์œผ๋ฉด ๋ฐ˜๋“œ์‹œ ํ—ˆ๋ฝ๋œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด์„œ๋งŒ์ด
๊ฐ€๋Šฅํ•˜๋‹ค.
โ€“์—ฌ๊ธฐ์—์„œ ํ—ˆ๋ฝ๋œ ์ธํ„ฐํŽ˜์ด์Šค๋ž€ ๊ฐ์ฒด๊ฐ€
์™ธ๋ถ€๋กœ ๊ณต๊ฐœํ•œ ๋ฉ”์„œ๋“œ๋ฅผ ๋œปํ•œ๋‹ค.
C++๋‚˜ Java์™€ ๊ฐ™์€ ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ๋Š” ๊ฐ์ฒด์˜ ์†์„ฑ์ด๋‚˜ ๋ฉ”์„œ๋“œ์—
์ ‘๊ทผ์„ ์ œ์–ดํ•˜๋Š” ์ ‘๊ทผ ์ง€์ •์ž (public, private, protected)๊ฐ€ ์ œ๊ณต๋œ๋‹ค.
โ€ขPython์—์„œ๋Š” ์ด๋Ÿฐ ์ ‘๊ทผ ์ง€์ •์ž๊ฐ€ ์—†๋‹ค.
โ€ขPython ํด๋ž˜์Šค์—์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  ๋ฉค๋ฒ„๊ฐ€ public์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.
โ€ขPython์—์„œ์˜ ์ ‘๊ทผ ์ง€์ •์€ ์ด๋ฆ„ ๊ทœ์น™์„ ํ†ตํ•ด ์ฒ˜๋ฆฌ๋˜๋ฉฐ, ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ์ ‘๊ทผ์ง€์ •์—
๋Œ€ํ•œ ์ฑ…์ž„์„ ์ง€๊ฒŒ ํ•œ๋‹ค.
โ€ขPython์—์„œ๋Š” ์ ‘๊ทผ ์ง€์ •์„ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด ๋ฐ‘์ค„( _ )์„ ์‚ฌ์šฉํ•œ๋‹ค.
Item 2: OOP
โ€“๋ฐ‘์ค„์ด ์—†์œผ๋ฉด : ๊ณต๊ฐœ ๋ชจ๋“œ๋กœ์„œ ๊ฐ์ฒด ์™ธ๋ถ€์—์„œ
์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
โ€“๋ฐ‘์ค„์ด ํ•˜๋‚˜์ด๋ฉด : ๊ฐ์ฒด ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•ด์„œ๋Š”
์•ˆ ๋œ๋‹ค.
โ€ข์ฝ”๋”ฉ ๊ด€๋ก€์ƒ ๋‚ด๋ถ€์ ์œผ๋กœ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ๋ณ€์ˆ˜ ๋˜๋Š”
๋ฉ”์„œ๋“œ์— ์‚ฌ์šฉ
โ€ข ๊ทธ๋Ÿฌ๋‚˜ public์ด๋ฏ€๋กœ ํ•„์š”ํ•˜๋ฉด ์™ธ๋ถ€์—์„œ
์—‘์„ธ์Šค ๊ฐ€๋Šฅ
โ€“๋ฐ‘์ค„์ด ๋‘ ๊ฐœ์ด๋ฉด : private ๋ชจ๋“œ๋กœ์„œ
๊ฐ์ฒด ์™ธ๋ถ€ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ƒ์†๋ฐ›์€ ๊ฐ์ฒด์—์„œ๋„
์ ‘๊ทผ์ด ์•ˆ ๋œ๋‹ค.
1 public mode
2 ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ ๋ฉ”์„œ๋“œ ํ†ตํ•ด ์ ‘๊ทผ ๊ถŒ์žฅ
3 private mode
Item 2: OOP
โ€ข๊ฐ์ฒด(object)
โ€“์†์„ฑ(Attribute)๊ณผ ํ–‰์œ„(Action)๋ฅผ ๊ฐ€์ง€๊ณ 
์žˆ์œผ๋ฉฐ ์ด๋ฆ„์„ ๋ถ™์ผ ์ˆ˜ ์žˆ๋Š” ๋ฌผ์ฒด
โ€ข์˜ˆ๋ฅผ ๋“ค์ž๋ฉด ์ž๋™์ฐจ, ํ•™์ƒ, ์Šค๋งˆํŠธ ํฐ, ๋ชจ
๋‹ˆํ„ฐ, ํ‚ค๋ณด๋“œ, ํ˜•๊ด‘๋“ฑ, ์ฑ…, ๋ฆฌ๋ชจ์ปจ ๋“ฑ
โ€ขํด๋ž˜์Šค(class)
โ€“๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์„ค๊ณ„๋„
โ€ข์ธ์Šคํ„ด์Šค(instance): ์„ค๊ณ„๋„์— ๋”ฐ๋ผ ์‹ค์ œ
๋กœ ๊ตฌํ˜„๋œ ๊ฒƒ
โ€ข์ธ์Šคํ„ด์Šค(instance)ํ™” = ์‹ค์ฒดํ™” = ๋ฉ”๋ชจ๋ฆฌ
์— ๊ตฌ์ถ•ํ•œ๋‹ค
โ€ขํด๋ž˜์Šค๋ฅผ ์‹ค์ฒดํ™” ํ˜น์€ ์ธ์Šคํ„ด์Šคํ™” ์‹œํ‚จ ๊ฒƒ
์ด ๊ฐ์ฒด์ด๋‹ค.
ex)
kim = Programmer()
์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด์ง„ kim์€ ๊ฐ์ฒด์ด๋ฉฐ,
kim์ด๋ผ๋Š” ๊ฐ์ฒด๋Š”
Programmer์˜ ์ธ์Šคํ„ด์Šค์ด๋‹ค.
Memory & Pointer
Memory & Pointer
Memory & Pointer
Memory & Pointer
https://www.youtube.com/watch?v=HEiPxjVR8CU
Memory & Pointer
https://www.youtube.com/watch?v=HEiPxjVR8CU
Memory & Pointer
https://www.youtube.com/watch?v=HEiPxjVR8CU
Memory & Pointer
https://www.youtube.com/watch?v=HEiPxjVR8CU
Memory & Pointer
https://www.youtube.com/watch?v=HEiPxjVR8CU
Memory & Pointer
https://www.youtube.com/watch?v=HEiPxjVR8CU
Memory & Pointer
Memory & Pointer
https://c10106.tistory.com/3046
Memory & Pointer
youtube.com/watch?v=gv-y9hIhvq4
Memory & Pointer
youtube.com/watch?v=gv-y9hIhvq4
Memory & Pointer
youtube.com/watch?v=gv-y9hIhvq4
Memory & Pointer
youtube.com/watch?v=gv-y9hIhvq4
Thank You

More Related Content

Similar to Effective Python

Game programming patterns 2
Game programming patterns 2Game programming patterns 2
Game programming patterns 2
QooJuice
ย 
Devon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐ
Devon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐDevon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐ
Devon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐ
Daum DNA
ย 
3 4 1
3 4 13 4 1
3 4 1
nexthw
ย 

Similar to Effective Python (20)

Java scriptแ„‹แ…ด แ„‹แ…ตแ„’แ…ข
Java scriptแ„‹แ…ด แ„‹แ…ตแ„’แ…ขJava scriptแ„‹แ…ด แ„‹แ…ตแ„’แ…ข
Java scriptแ„‹แ…ด แ„‹แ…ตแ„’แ…ข
ย 
๋””์ž์ธํŒจํ„ด 1~13
๋””์ž์ธํŒจํ„ด 1~13๋””์ž์ธํŒจํ„ด 1~13
๋””์ž์ธํŒจํ„ด 1~13
ย 
Head first๋””์ž์ธํŒจํ„ด 1~13_ํฌ๋ฏผ_ํ˜ธ์ค€
Head first๋””์ž์ธํŒจํ„ด 1~13_ํฌ๋ฏผ_ํ˜ธ์ค€Head first๋””์ž์ธํŒจํ„ด 1~13_ํฌ๋ฏผ_ํ˜ธ์ค€
Head first๋””์ž์ธํŒจํ„ด 1~13_ํฌ๋ฏผ_ํ˜ธ์ค€
ย 
9 object class
9 object class9 object class
9 object class
ย 
Flask! - python web framework flask ํŠœํ† ๋ฆฌ์–ผ
Flask! - python web framework flask ํŠœํ† ๋ฆฌ์–ผFlask! - python web framework flask ํŠœํ† ๋ฆฌ์–ผ
Flask! - python web framework flask ํŠœํ† ๋ฆฌ์–ผ
ย 
[ 2015 SOSCON ]แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ณแ„แ…ขแ†จ swiftแ„…แ…ฉ แ„‰แ…ตแ„Œแ…กแ†จแ„’แ…กแ„‚แ…ณแ†ซ แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ฉแ„‰แ…ณ แ„‡แ…ฎแ†ซแ„‰แ…ฅแ†จ แ„‰แ…กแ†ธแ„Œแ…ตแ†ฏแ„€แ…ต
[ 2015 SOSCON ]แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ณแ„แ…ขแ†จ swiftแ„…แ…ฉ แ„‰แ…ตแ„Œแ…กแ†จแ„’แ…กแ„‚แ…ณแ†ซ แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ฉแ„‰แ…ณ แ„‡แ…ฎแ†ซแ„‰แ…ฅแ†จ แ„‰แ…กแ†ธแ„Œแ…ตแ†ฏแ„€แ…ต[ 2015 SOSCON ]แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ณแ„แ…ขแ†จ swiftแ„…แ…ฉ แ„‰แ…ตแ„Œแ…กแ†จแ„’แ…กแ„‚แ…ณแ†ซ แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ฉแ„‰แ…ณ แ„‡แ…ฎแ†ซแ„‰แ…ฅแ†จ แ„‰แ…กแ†ธแ„Œแ…ตแ†ฏแ„€แ…ต
[ 2015 SOSCON ]แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ณแ„แ…ขแ†จ swiftแ„…แ…ฉ แ„‰แ…ตแ„Œแ…กแ†จแ„’แ…กแ„‚แ…ณแ†ซ แ„‹แ…ฉแ„‘แ…ณแ†ซแ„‰แ…ฉแ„‰แ…ณ แ„‡แ…ฎแ†ซแ„‰แ…ฅแ†จ แ„‰แ…กแ†ธแ„Œแ…ตแ†ฏแ„€แ…ต
ย 
Effective C++ Chapter 3 Summary
Effective C++ Chapter 3 SummaryEffective C++ Chapter 3 Summary
Effective C++ Chapter 3 Summary
ย 
2015 SW๋งˆ์—์ŠคํŠธ๋กœ 100+ ์ปจํผ๋Ÿฐ์Šค_์˜คํ”ˆ์Šคํƒ Swift๋กœ ์‹œ์ž‘ํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค ๋ถ„์„ ์‚ฝ์งˆ๊ธฐ
2015 SW๋งˆ์—์ŠคํŠธ๋กœ 100+ ์ปจํผ๋Ÿฐ์Šค_์˜คํ”ˆ์Šคํƒ Swift๋กœ ์‹œ์ž‘ํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค ๋ถ„์„ ์‚ฝ์งˆ๊ธฐ2015 SW๋งˆ์—์ŠคํŠธ๋กœ 100+ ์ปจํผ๋Ÿฐ์Šค_์˜คํ”ˆ์Šคํƒ Swift๋กœ ์‹œ์ž‘ํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค ๋ถ„์„ ์‚ฝ์งˆ๊ธฐ
2015 SW๋งˆ์—์ŠคํŠธ๋กœ 100+ ์ปจํผ๋Ÿฐ์Šค_์˜คํ”ˆ์Šคํƒ Swift๋กœ ์‹œ์ž‘ํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค ๋ถ„์„ ์‚ฝ์งˆ๊ธฐ
ย 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
ย 
Spring di chapter2
Spring di chapter2Spring di chapter2
Spring di chapter2
ย 
[์Šคํ”„๋ง ์Šคํ„ฐ๋”” 1์ผ์ฐจ] ์˜ค๋ธŒ์ ํŠธ์™€ ์˜์กด๊ด€๊ณ„
[์Šคํ”„๋ง ์Šคํ„ฐ๋”” 1์ผ์ฐจ] ์˜ค๋ธŒ์ ํŠธ์™€ ์˜์กด๊ด€๊ณ„[์Šคํ”„๋ง ์Šคํ„ฐ๋”” 1์ผ์ฐจ] ์˜ค๋ธŒ์ ํŠธ์™€ ์˜์กด๊ด€๊ณ„
[์Šคํ”„๋ง ์Šคํ„ฐ๋”” 1์ผ์ฐจ] ์˜ค๋ธŒ์ ํŠธ์™€ ์˜์กด๊ด€๊ณ„
ย 
Game programming patterns 2
Game programming patterns 2Game programming patterns 2
Game programming patterns 2
ย 
Java class
Java classJava class
Java class
ย 
Java_05 class
Java_05 classJava_05 class
Java_05 class
ย 
PyCon 12์›” ์„ธ๋ฏธ๋‚˜ - ์‹ค์ „ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑ… ํ™๋ณด
PyCon 12์›” ์„ธ๋ฏธ๋‚˜ - ์‹ค์ „ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑ… ํ™๋ณดPyCon 12์›” ์„ธ๋ฏธ๋‚˜ - ์‹ค์ „ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑ… ํ™๋ณด
PyCon 12์›” ์„ธ๋ฏธ๋‚˜ - ์‹ค์ „ ํŒŒ์ด์ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฑ… ํ™๋ณด
ย 
Devon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐ
Devon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐDevon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐ
Devon 2011-b-5 ํšจ๊ณผ์ ์ธ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋‹ค๋ฃจ๊ธฐ
ย 
๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ณธ
๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ณธ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ณธ
๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ณธ
ย 
3 4 1
3 4 13 4 1
3 4 1
ย 
Python class
Python classPython class
Python class
ย 
Python ์ƒํƒœ๊ณ„์˜ ์ดํ•ด
Python ์ƒํƒœ๊ณ„์˜ ์ดํ•ดPython ์ƒํƒœ๊ณ„์˜ ์ดํ•ด
Python ์ƒํƒœ๊ณ„์˜ ์ดํ•ด
ย 

More from SEMINARGROOT

Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.
SEMINARGROOT
ย 

More from SEMINARGROOT (20)

Metric based meta_learning
Metric based meta_learningMetric based meta_learning
Metric based meta_learning
ย 
Sampling method : MCMC
Sampling method : MCMCSampling method : MCMC
Sampling method : MCMC
ย 
Demystifying Neural Style Transfer
Demystifying Neural Style TransferDemystifying Neural Style Transfer
Demystifying Neural Style Transfer
ย 
Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.
ย 
The ways of node embedding
The ways of node embeddingThe ways of node embedding
The ways of node embedding
ย 
Graph Convolutional Network
Graph  Convolutional NetworkGraph  Convolutional Network
Graph Convolutional Network
ย 
Denoising With Frequency Domain
Denoising With Frequency DomainDenoising With Frequency Domain
Denoising With Frequency Domain
ย 
Bayesian Statistics
Bayesian StatisticsBayesian Statistics
Bayesian Statistics
ย 
Coding Test Review 3
Coding Test Review 3Coding Test Review 3
Coding Test Review 3
ย 
Time Series Analysis - ARMA
Time Series Analysis - ARMATime Series Analysis - ARMA
Time Series Analysis - ARMA
ย 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine Learning
ย 
Generative models : VAE and GAN
Generative models : VAE and GANGenerative models : VAE and GAN
Generative models : VAE and GAN
ย 
Understanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsUnderstanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence Functions
ย 
Attention Is All You Need
Attention Is All You NeedAttention Is All You Need
Attention Is All You Need
ย 
Attention
AttentionAttention
Attention
ย 
WWW 2020 XAI Tutorial Review
WWW 2020 XAI Tutorial ReviewWWW 2020 XAI Tutorial Review
WWW 2020 XAI Tutorial Review
ย 
Coding test review 2
Coding test review 2Coding test review 2
Coding test review 2
ย 
Locality sensitive hashing
Locality sensitive hashingLocality sensitive hashing
Locality sensitive hashing
ย 
Coding Test Review1
Coding Test Review1Coding Test Review1
Coding Test Review1
ย 
Strong convexity on gradient descent and newton's method
Strong convexity on gradient descent and newton's methodStrong convexity on gradient descent and newton's method
Strong convexity on gradient descent and newton's method
ย 

Effective Python

  • 1.
  • 5. What we will cover
  • 6. What we will cover
  • 7. What we will cover
  • 8. Ch1 Pythonic Thinking : How we write a โ€œclean codeโ€
  • 9. Item 2: Follow the PEP 8 Style Guide Python Enhancement Proposal #8 a wealth of details about how to write clear Python code. updated as the Python language evolves. http://www.python.org/dev/peps/pep-0008/
  • 10. Item 2: Follow the PEP 8 Style Guide https://www.slideshare.net/japh44/type-annotations-in-python-whats-whys-and-wows
  • 11. Item 2: Follow the PEP 8 Style Guide https://www.slideshare.net/japh44/type-annotations-in-python-whats-whys-and-wows
  • 12. Item 2: Follow the PEP 8 Style Guide
  • 13. Item 2: Follow the PEP 8 Style Guide
  • 15. Item 2: OOP ํด๋ž˜์Šค(class) ๋ฉ”์„œ๋“œ โ€“ ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋”ฐ๋ผ์„œ ๊ฐ์ฒด์˜ ์ƒ์„ฑ ์—†์ด๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. (๊ฐ์ฒด์™€ ๋ฌด๊ด€ํ•˜๋ฏ€๋กœ self๊ฐ€ ์—†์Œ์— ์œ ์˜) โ€“ ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์—์„œ ๊ฐ์ฒด์˜ ์†์„ฑ์„ ์ ‘๊ทผํ•˜๊ฑฐ๋‚˜ ์‚ฌ์šฉํ•˜๋ ค๋Š” ํ–‰์œ„๋Š” ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค. (๊ฐ์ฒด์™€ ๊ด€๋ จ์ด ์—†๋‹ค) โ€“ cls ๋ผ๋Š” ํด๋ž˜์Šค๋ฅผ ์˜๋ฏธํ•˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌ๋ฐ›์•„, ํด๋ž˜์Šค ๋ณ€์ˆ˜ ๋“ฑ์„ ์•ก์„ธ์Šค ํ•  ์ˆ˜ ์žˆ ๋‹ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋กœ๋Š” ํด๋ž˜์Šค ์ž์‹ ์ด ์ž๋™์œผ๋กœ ์ „๋‹ฌ๋˜๊ณ  ์ด ์ธ์ˆ˜๋ฅผ 'cls'๋ผ๊ณ  ํ•œ๋‹ค โ€“ ๋ฉ”์„œ๋“œ ์•ž์— @classmethod ๋ผ๋Š” Decorator๋ฅผ ํ‘œ์‹œ ์ธ์Šคํ„ด์Šค(Instance) ๋ฉ”์„œ๋“œ โ€“ ๊ฐ์ฒด(์ธ์Šคํ„ด์Šค)๋ฅผ ํ†ตํ•ด์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์„œ๋“œ โ€“ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ ์ดํ›„์— ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ ์ฃผ๋กœ ๊ฐ์ฒด์˜ ์†์„ฑ์„ ์กฐ์ž‘, ๊ด€๋ฆฌ ๋ฐ ์ •๋ณด์˜ ์ƒ ์„ฑ์— ์ด์šฉ๋œ๋‹ค. โ€“ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜์— ์—‘์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฉ”์„œ๋“œ์˜ ์ฒซ๋ฒˆ์งธ ํŒŒ๋ผ๋ฏธํ„ฐ์— ํ•ญ์ƒ ๊ฐ์ฒด ์ž์‹ ์„ ์˜๋ฏธํ•˜๋Š” "self"๋ผ๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ–๋Š”๋‹ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ ์ธ์ž self๋กœ ์ธ์Šคํ„ด์Šค ์ž์‹ ์ด ์ž๋™ ์œผ๋กœ ํ˜ธ์ถœ๋œ๋‹ค.
  • 18. Item 2: OOP ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜: ํด๋ž˜์Šค ์ •์˜์—์„œ ๋ฉ” ์„œ๋“œ ์•ˆ์—์„œ ์‚ฌ์šฉ๋˜๋ฉด์„œ "self.๋ณ€์ˆ˜๋ช…"์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋˜๋ฉฐ, ์ด๋Š” ๊ฐ ๊ฐ์ฒด ๋ณ„๋กœ ์„œ๋กœ ๋‹ค๋ฅธ ๊ฐ’์„ ๊ฐ–๋Š” ๋ณ€์ˆ˜์ด๋‹ค. ํด๋ž˜์Šค ๋ณ€์ˆ˜๊ฐ€ ํ•˜๋‚˜์˜ ํด๋ž˜์Šค์— ํ•˜๋‚˜๋งŒ ์กด์žฌํ•˜๋Š” ๋ฐ˜๋ฉด, ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋Š” ๊ฐ ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค๋งˆ๋‹ค ๋ณ„๋„๋กœ ์กด์žฌํ•œ๋‹ค.
  • 19. Item 2: OOP self๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐ์ฒด ์ž์‹ ์ด ๊ฐ€์ง„ ์†์„ฑ์„ ๋ณ€ํ™”์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ์ฒด์˜ ์†์„ฑ ๊ฐ’์ด ์ •ํ™•ํ•˜๊ฒŒ ๊ด€๋ฆฌ๋œ๋‹ค.
  • 20. Item 2: OOP โ€ข์บก์Šํ™”(encapsulation)๋Š” ๊ฐ์ฒด์˜ ์™ธ๋ถ€์—์„œ ๊ฐ ์ฒด ๋‚ด๋ถ€์˜ ์†์„ฑ์„ ์ง์ ‘์ ์œผ๋กœ ์ ‘๊ทผ, ์†์„ฑ์„ ์ฝ๊ฑฐ ๋‚˜ ๋ณ€๊ฒฝ์‹œํ‚ค์ง€ ๋ชปํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค. โ€ข๊ฐ์ฒด์˜ ์†์„ฑ์„ ์ ‘๊ทผ, ์†์„ฑ์„ ์ฝ๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์œผ๋ฉด ๋ฐ˜๋“œ์‹œ ํ—ˆ๋ฝ๋œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด์„œ๋งŒ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. โ€“์—ฌ๊ธฐ์—์„œ ํ—ˆ๋ฝ๋œ ์ธํ„ฐํŽ˜์ด์Šค๋ž€ ๊ฐ์ฒด๊ฐ€ ์™ธ๋ถ€๋กœ ๊ณต๊ฐœํ•œ ๋ฉ”์„œ๋“œ๋ฅผ ๋œปํ•œ๋‹ค. C++๋‚˜ Java์™€ ๊ฐ™์€ ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ๋Š” ๊ฐ์ฒด์˜ ์†์„ฑ์ด๋‚˜ ๋ฉ”์„œ๋“œ์— ์ ‘๊ทผ์„ ์ œ์–ดํ•˜๋Š” ์ ‘๊ทผ ์ง€์ •์ž (public, private, protected)๊ฐ€ ์ œ๊ณต๋œ๋‹ค. โ€ขPython์—์„œ๋Š” ์ด๋Ÿฐ ์ ‘๊ทผ ์ง€์ •์ž๊ฐ€ ์—†๋‹ค. โ€ขPython ํด๋ž˜์Šค์—์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  ๋ฉค๋ฒ„๊ฐ€ public์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค. โ€ขPython์—์„œ์˜ ์ ‘๊ทผ ์ง€์ •์€ ์ด๋ฆ„ ๊ทœ์น™์„ ํ†ตํ•ด ์ฒ˜๋ฆฌ๋˜๋ฉฐ, ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ์ ‘๊ทผ์ง€์ •์— ๋Œ€ํ•œ ์ฑ…์ž„์„ ์ง€๊ฒŒ ํ•œ๋‹ค. โ€ขPython์—์„œ๋Š” ์ ‘๊ทผ ์ง€์ •์„ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด ๋ฐ‘์ค„( _ )์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • 21. Item 2: OOP โ€“๋ฐ‘์ค„์ด ์—†์œผ๋ฉด : ๊ณต๊ฐœ ๋ชจ๋“œ๋กœ์„œ ๊ฐ์ฒด ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. โ€“๋ฐ‘์ค„์ด ํ•˜๋‚˜์ด๋ฉด : ๊ฐ์ฒด ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•ด์„œ๋Š” ์•ˆ ๋œ๋‹ค. โ€ข์ฝ”๋”ฉ ๊ด€๋ก€์ƒ ๋‚ด๋ถ€์ ์œผ๋กœ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ๋ณ€์ˆ˜ ๋˜๋Š” ๋ฉ”์„œ๋“œ์— ์‚ฌ์šฉ โ€ข ๊ทธ๋Ÿฌ๋‚˜ public์ด๋ฏ€๋กœ ํ•„์š”ํ•˜๋ฉด ์™ธ๋ถ€์—์„œ ์—‘์„ธ์Šค ๊ฐ€๋Šฅ โ€“๋ฐ‘์ค„์ด ๋‘ ๊ฐœ์ด๋ฉด : private ๋ชจ๋“œ๋กœ์„œ ๊ฐ์ฒด ์™ธ๋ถ€ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ƒ์†๋ฐ›์€ ๊ฐ์ฒด์—์„œ๋„ ์ ‘๊ทผ์ด ์•ˆ ๋œ๋‹ค. 1 public mode 2 ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ ๋ฉ”์„œ๋“œ ํ†ตํ•ด ์ ‘๊ทผ ๊ถŒ์žฅ 3 private mode
  • 22. Item 2: OOP โ€ข๊ฐ์ฒด(object) โ€“์†์„ฑ(Attribute)๊ณผ ํ–‰์œ„(Action)๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ ์ด๋ฆ„์„ ๋ถ™์ผ ์ˆ˜ ์žˆ๋Š” ๋ฌผ์ฒด โ€ข์˜ˆ๋ฅผ ๋“ค์ž๋ฉด ์ž๋™์ฐจ, ํ•™์ƒ, ์Šค๋งˆํŠธ ํฐ, ๋ชจ ๋‹ˆํ„ฐ, ํ‚ค๋ณด๋“œ, ํ˜•๊ด‘๋“ฑ, ์ฑ…, ๋ฆฌ๋ชจ์ปจ ๋“ฑ โ€ขํด๋ž˜์Šค(class) โ€“๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์„ค๊ณ„๋„ โ€ข์ธ์Šคํ„ด์Šค(instance): ์„ค๊ณ„๋„์— ๋”ฐ๋ผ ์‹ค์ œ ๋กœ ๊ตฌํ˜„๋œ ๊ฒƒ โ€ข์ธ์Šคํ„ด์Šค(instance)ํ™” = ์‹ค์ฒดํ™” = ๋ฉ”๋ชจ๋ฆฌ ์— ๊ตฌ์ถ•ํ•œ๋‹ค โ€ขํด๋ž˜์Šค๋ฅผ ์‹ค์ฒดํ™” ํ˜น์€ ์ธ์Šคํ„ด์Šคํ™” ์‹œํ‚จ ๊ฒƒ ์ด ๊ฐ์ฒด์ด๋‹ค. ex) kim = Programmer() ์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด์ง„ kim์€ ๊ฐ์ฒด์ด๋ฉฐ, kim์ด๋ผ๋Š” ๊ฐ์ฒด๋Š” Programmer์˜ ์ธ์Šคํ„ด์Šค์ด๋‹ค.