# 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