-
[OOP] class 클래스 개념 및 구성요소🐍 파이썬/파이썬 기본 문법 2022. 7. 27. 11:30
What is "Object-oriented" programming?
•"Object-orientation" is just one of many programming paradigms
: Our world is made up of "things", so it is a good model of the world!
•Practical considerations:
-Facilitates testing(we can test the classes separately)
-Encourages reuse(we can reuse classes defined by other people)
-Users don’t need to know the inner workings of a class, they just rely on the public interface (= data and function attributes)
-It is possible to hide information that users don’t need to understand
-Class can InheritData and Behavior From Parent Class
What is a Class? What is an Object?
- A class is like a blueprint and objects are concrete instances
- Objects of the same class have the same attributes and functions
- Everything in Python is Object !
Class definition
The type of an object is its class
Constructor : definining data attributes
When creating an object (a.k.a. instantiation, construction), the __init__function is called.
This is used to:
•Define data attributes upon object creation
•Run any other code that needs to be run upon object creation
•The first parameter, self, points to the instance
•Data attributes are also called instance variables
Instantiation and access to data attributes
Class variables (!= not instance variables)
Methods are Functions Defined In A Class
Static methods
Instance variables can be made "private"
So what is "self"?
'🐍 파이썬 > 파이썬 기본 문법' 카테고리의 다른 글
[inheritance] 상속 with 예제 (0) 2022.07.28 [class] python-specific special method (0) 2022.07.27 [list] reference and copy (aliasing and clone) (0) 2022.07.19 [List] 자주쓰이는 리스트 메소드 정리 (0) 2022.07.19 [concept] list vs tuple (0) 2022.07.19