반응형
class Account:
num_accounts = 0
def __init__(self, name):
self.name = name
Account.num_accounts +=1
def __del__(self):
Account.num_accounts -=1
kim = Account('Chang')
lee = Account('Kim')
print(kim.name)
print(lee.name)
print(kim.num_accounts)
실행결과
$ py class_instance.py
Chang
Kim
2
반응형
'Programming > Python' 카테고리의 다른 글
[Python-Basic] Class Data Type - 3(Inheritance) (0) | 2019.11.05 |
---|---|
[Python-Basic] Class Data Type - 3(Constructor) (0) | 2019.11.05 |
[Python-Basic] Class Data Type - 1 (0) | 2019.11.05 |
[Python-Basic] Tuple Data Type - 1 (0) | 2019.11.05 |
[Python-Basic] Tuple Data Type - 2 (Index) (0) | 2019.11.05 |