Last active
January 27, 2019 11:56
-
-
Save Geekfish/221ffd2ea543f03ea78d712bcc46c08b to your computer and use it in GitHub Desktop.
Straight into the interpreter, vs in function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3 | |
Python 3.7.0 (default, Jul 23 2018, 20:24:19) | |
[Clang 9.0.0 (clang-900.0.39.2)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> class C(): | |
... def __init__(self, i): | |
... print(f"contructing {i}") | |
... self.i = i | |
... def __del__(self): | |
... print(f"deleting {self.i}") | |
... | |
>>> for i in range(5): | |
... C(i) | |
... | |
contructing 0 | |
<__main__.C object at 0x102a26898> | |
contructing 1 | |
deleting 0 | |
<__main__.C object at 0x102a26828> | |
contructing 2 | |
deleting 1 | |
<__main__.C object at 0x102a26898> | |
contructing 3 | |
deleting 2 | |
<__main__.C object at 0x102a26828> | |
contructing 4 | |
deleting 3 | |
<__main__.C object at 0x102a26898> | |
>>> def unused(): | |
... for i in range(5): | |
... C(i) | |
... | |
>>> unused() | |
contructing 0 | |
deleting 0 | |
contructing 1 | |
deleting 1 | |
contructing 2 | |
deleting 2 | |
contructing 3 | |
deleting 3 | |
contructing 4 | |
deleting 4 | |
>>> (Exiting with Ctrl+D) | |
deleting 4 <- this probably comes from the first loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment