Make Dog a dataclass and create three dogs
This commit is contained in:
parent
f58b645186
commit
4a4497bf8e
1 changed files with 13 additions and 0 deletions
13
heaven.py
13
heaven.py
|
|
@ -1,6 +1,19 @@
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class Dog:
|
class Dog:
|
||||||
|
name: str
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
global heaven
|
global heaven
|
||||||
heaven.append(self)
|
heaven.append(self)
|
||||||
|
|
||||||
|
|
||||||
heaven = []
|
heaven = []
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
Dog("Fido")
|
||||||
|
Dog("Rex")
|
||||||
|
Dog("Spot")
|
||||||
|
print(heaven)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue