class SomeClass:
def __init__(self,something):
self.something = something
def some_function(self):
print(self.something)
a = SomeClass("some_value")
a.some_function();
⇒ 클래스 구성 시 정형적인 구문 (인스턴스 자체)
⇒ 클래스의 생성자 (constructor)
__init__()
은 반드시 첫번째 인수로 self를 지정해야 함⇒ 클래스 인스턴스 호출 시 실행되는 메소드
class Calc:
def __init__(self, n1, n2):
self.n1 = n1
self.n2 = n2
return print(self.n1, self.n2)
def __call__(self, n1, n2):
self.n1 = n1
self.n2 = n2
return print(self.n1 + self.n2)
s = Calc(1,2) #출력 : 1 2
s(7,8) #출력 : 15
참고:
https://engineer-mole.tistory.com/190 [매일 꾸준히, 더 깊이]
https://wjunsea.tistory.com/m/61