Python function destruction

Source: Internet
Author: User
Tags garbage collection


# function Destroy
# Global Function Destruction
# redefine function with the same name
# del statement Delete function object
# at the end of the program
def foo (xyz=[], u= ' abc ', Z=123):
Xyz.append (1)
return XYZ
Print (ID (foo))

def foo (xyz=[]):
Xyz.append (1)
return XYZ
Print (foo) # foo function ID changed, last foo function waiting for garbage collection

del foo
Print (ID (foo))

# Local Function Destruction
# re-define a function with the same name in the ancestor scope
# del statement Delete function object
# When a parent scope is destroyed
def foo (xyz=[], u= ' abc ', Z=123):
Xyz.append (1)
def inner (a=10):
Pass
Print (ID (inner))
def inner (a=100):
Print (XYZ)
Print (ID (inner))
return inner

bar = foo ()
Print (ID (foo), ID (bar), foo.__defaults__, bar.__defaults__)
Del Bar
Print (ID (foo), ID (bar), foo.__defaults__, bar.__defaults__)

Python function Destruction

Related Article

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.