Python destructors and special call methods

Source: Internet
Author: User
#-*-Coding:utf-8-*-"" "Created on Sun Nov 23:19:03 @author: Toby" "" #知识点: Destructors and Special __call__ method "' enough to function: where" __del__ "is is a destructor, when you use Del to delete an object, it calls his own destructor, and when the object is called in a scope, the destructor is also called once when it is out of scope, which can be used to free up memory space. ' Class Foo:    def __init__ (self):        pass         def __del__ (self): #析构函数 __del__ function is always executed at the end of the        print ' Destroy '             def Go:        print ' Go '                   def __call__ (self):         print ' call ' F1 = Foo () #实例化对象f1. Go () #执行go方法f1 ()    # The call here is actually directly executing the code inside the __call__ method.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.