コンストラクタとデストラクタ
3403 ワード
コンストラクタ
オブジェクトを作る初めのときに呼ばれるもの
qiita.py
class Person(object):
def __init__(self,name):
self.name = name
デストラクタ
オブジェクトがなくなるときに呼ぶ物
使われなくなったときに呼び出される
qiita.py
class Person(object):
def __init__(self,name):
self.name = name
def say_something(self):
print("I am {}. hello".format(self.name))
self.run()
def run(self):
print("run")
#ここがデストラクタ
def __del__(self):
print("good bye")
明示的に使いたい場合
qiita.py
del person
Author And Source
この問題について(コンストラクタとデストラクタ), 我々は、より多くの情報をここで見つけました https://qiita.com/kirinboy96/items/e663b61aebb9e7f0b485著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .