Class and Method
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
Author And Source
이 문제에 관하여(Class and Method), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@padahkim/Class-and-Method저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)