pythonにも構造関数があり、驚きました.

375 ワード

class Car(object):
    def __init__(self):
        print '---ok---'

    def __del__(self):
        print '----deconstrcut-------'


c =  Car()

実行結果
---ok--- ----deconstrcut-------
これは確かに構造関数が実行されたことを証明しており,後で見ると,いくつかの論理を構造関数に置くことができる.
リファレンスドキュメント
https://docs.python.org/2/reference/datamodel.html