python解構函式和特殊的call方法

來源:互聯網
上載者:User
# -*- coding: utf-8 -*-"""Created on Sun Nov 13 23:19:03 2016 @author: toby"""#知識點:解構函式和特殊的__call__方法'''析夠函數:其中的“__del__”就是一個解構函式了,當使用del 刪除對象時,會調用他本身的解構函式,另外當對象在某個範圍中調用完畢,在跳出其範圍的同時解構函式也會被調用一次,這樣可以用來釋放記憶體空間。'''class Foo:    def __init__(self):        pass         def __del__(self): #解構函式 __del__函數永遠是在最後執行        print '銷毀'             def go(self):        print 'go'                   def __call__(self):         print 'call' f1 = Foo() #執行個體化對象f1.go() #執行go方法f1()    #這裡的調用實際上是直接執行__call__方法裡面的代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.