생성자
📌 생성자
: 객체가 생성될 때 자동으로 호출되는 메서드.
__init__으로 이름을 사용해야 생성자로 인식함.
class Test:
def __init(self):
pass
소멸자
📌 소멸자
: 객체 레퍼런스 카운트가 0이 될 때 호출되는 메서드.
__del__으로 이름을 사용해야 소멸자로 인식함.
class Test:
def __init__(self):
print("Test __init__()")
def __del__(self):
print("Tesst __del__()")
t = Test()
# Test __init__()
# Test __del__()
'Python > Python' 카테고리의 다른 글
[Python] 예외처리 - try except문, try finally, try else문 (0) | 2022.10.04 |
---|---|
[Python] 파일입출력 (0) | 2022.10.04 |
[Python] dict (0) | 2022.09.27 |
[Python] set (0) | 2022.09.27 |
[Python] class (0) | 2022.09.26 |
댓글