본문 바로가기

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' 카테고리의 다른 글