1. Class = BluePrint 설계도 int(),list(),dict()등도 사실은 클래스
2. 이 Class(설계도)를 이용해서 만든 결과물이 instances(객체)
3. Class안에 있는 함수를 Method라고 함
4. Method호출시에는 Class가 아니라 Instances를 이용하여 호출
ex)
a = list(range(10))
a.append(x)
-파이썬은 Method를 호출할 때 그 method의 instances를 자신의 첫번째 arg(self)로 사용
밑의 코드에서 tesla.start()를 호출시
class Car(arg):
...
...
tesla.start(tesla)와 동일한 연산을 파이썬 내부적으로 실행(start method called by tesla)
class Car():
wheels = 4
doors = 4
windows = 4
seats = 2``` def start(self): print(self) print(self.color) print(self.doors) ```
tesla = Car()
tesla.color = "Red hot red"
tesla.start()
실행결과
<main.Car object at 0x7f12db05d3a0>
Red hot red
4