May-15-2021, 02:57 PM
Hello all
I was wondering if anyone could help shed some light on how to manage objects once they have been instantiated.
I have a class that creates a person that takes various attributes and uses 2 x methods, the code is as follows:-
Also is there any way of determining how many objects have been created by a class?
Thank you.
I was wondering if anyone could help shed some light on how to manage objects once they have been instantiated.
I have a class that creates a person that takes various attributes and uses 2 x methods, the code is as follows:-
from datetime import date class Human(): def __init__(self, name, sex, eyecolor, height, yearborn): self.name = name self.sex = sex self.eyecolor = eyecolor self.height = height self.yearborn = yearborn print("Object", self.name, self.sex, self.eyecolor, self.height, self.yearborn, "Has been created") def age(self): currentdate = date.today() a = currentdate.year - self.yearborn return a def display(self): print(self.name) print(self.sex) print(self.eyecolor) print(self.height) print(self.yearborn)I create the object using the code:-
Tom = test.Human("Tom","Male", "Green",178,1989)After the I have performed, for example, calculating the age then what do I with the object if I no longer need it - do I delete the object, can I safety forget about it - does it just sit in memory?
Also is there any way of determining how many objects have been created by a class?
Thank you.