SlideShare a Scribd company logo
Effective Python
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

PDF
Start IoT with JavaScript - 7.프로토타입
PPTX
파이썬+객체지향+이해하기 20160131
PPTX
파이썬+클래스+구조+이해하기 20160310
PPT
Python class
PPTX
파이썬 namespace Binding 이해하기
PDF
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018
PDF
파이썬 모듈 패키지
PDF
Light Tutorial Python
Start IoT with JavaScript - 7.프로토타입
파이썬+객체지향+이해하기 20160131
파이썬+클래스+구조+이해하기 20160310
Python class
파이썬 namespace Binding 이해하기
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018
파이썬 모듈 패키지
Light Tutorial Python

Similar to Effective Python (20)

PPTX
파이썬 객체 클래스 이해하기
PDF
Python class
PDF
Smalltalk at Altlang 2008
PDF
[PyCon Korea 2019] 파이썬의 변수
PDF
스칼라 클래스 이해하기 _Scala class understanding
PDF
PyCon 12월 세미나 - 실전 파이썬 프로그래밍 책 홍보
PPTX
파이썬 class 및 function namespace 이해하기
PDF
Python Programming: Function
PPTX
OOP - Object Oriendted Programing
PPTX
파이썬 심화
PPTX
python data model 이해하기
PDF
M5 6 1
PDF
C++에서 Objective-C까지 번역자료
PPT
Python3 brief summary
PPTX
파이썬 Special method 이해하기
PPTX
[자바카페] 자바 객체지향 프로그래밍 (2017)
PDF
Python Programming: Class and Object Oriented Programming
PPTX
깨끗한 코드 (클린 코드, Clean Code)
PDF
PPT
effective c++ chapter 3~4 정리
파이썬 객체 클래스 이해하기
Python class
Smalltalk at Altlang 2008
[PyCon Korea 2019] 파이썬의 변수
스칼라 클래스 이해하기 _Scala class understanding
PyCon 12월 세미나 - 실전 파이썬 프로그래밍 책 홍보
파이썬 class 및 function namespace 이해하기
Python Programming: Function
OOP - Object Oriendted Programing
파이썬 심화
python data model 이해하기
M5 6 1
C++에서 Objective-C까지 번역자료
Python3 brief summary
파이썬 Special method 이해하기
[자바카페] 자바 객체지향 프로그래밍 (2017)
Python Programming: Class and Object Oriented Programming
깨끗한 코드 (클린 코드, Clean Code)
effective c++ chapter 3~4 정리
Ad

More from SEMINARGROOT (20)

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

Effective Python