본문 바로가기

Python

[Python] 생성자(Constructor)

객체가 생성될 때 자동으로 호출되는 코드

주로 초기화에 사용됨

 

class Cal:
    def __init__(self, b, c) -> None:
        self.b = b
        self.c = c

    def printFunc(self):
        print(self.b)
        print(self.c)

a = Cal([1,2], 65)

a.printFunc()

 

반응형

'Python' 카테고리의 다른 글

[Python] 클래스 상속 / 오버라이딩 / 클래스 변수  (0) 2022.01.22
[Python] Function Annotation  (0) 2022.01.21
[Python] 클래스 (class)  (0) 2022.01.20
[Python] print()  (0) 2022.01.20
[Python] console 통해서 데이터 input 받기  (0) 2022.01.20