-컨스트럭터라고 불리는 초기화를 위한 함수(메소드)
-인스턴스화를 실시할 때 반드시 처음에 호출되는 특수한 함수
-오브젝트 생성(인스턴스 생성)과 관련하여 데이터 초기화를 실시하는 함수
__init__( ) 은 반드시 첫번째 인수로 self를 지정해야 함. self에는 인스턴스 자체가 전달되어 있음.
class SomeClass:
def __init__(self,something):#constructor
self.something = something
출처: https://engineer-mole.tistory.com/190 [매일 꾸준히, 더 깊이:티스토리]
class MyStatus:
def __init__(self,age,name,height,weight):
self.age = age
self.name = name
self.height = height
self.weight = weight
def print_name(self):
print(self.name)
def print_age(self):
print(self.age)
def print_height(self):
print(self.height)
def print_weight(self):
print(self.weight)
a = MyStatus(34,"yamada",170,78)
출처: https://engineer-mole.tistory.com/190 [매일 꾸준히, 더 깊이:티스토리]
'개념 정리 > 문법 정리' 카테고리의 다른 글
파이썬 불 자료형(bool Data type) (0) | 2022.06.18 |
---|---|
파이썬 = 과 = = 차이 (0) | 2022.06.18 |
파이썬 (Dictionary형태) (0) | 2022.06.17 |
cd(명령프롬프트) 정리 (0) | 2022.06.17 |
Class 클래스 (0) | 2022.06.15 |