Variables are created when the file is imported.
An instance of the class is destroyed when the function finishes.
class A:
def __init__(self):
self.a = 'a'
self.b = 'b'
def __del__(self):
print(self.__dict__)
def main():
a = A()
main()
-> {'a': 'a', 'b': 'b'}
__del__
is executed when the class instance is destroyed.
(main ()
is executed, and when the process is finished, the instance is destroyed and print is executed.)
Recommended Posts