delete the object of the class in python by R4R Team

- When object is created then some Heap area are allocated to it.
- So if we want to free that area of memory then we delete the object of the class

Syntax-

del(object)


program-

#create class
class Computer():
def __init__(self):
print("Object is created")

def function(self):
print("Function is called")

#create object
c1=Computer()
c2=Computer()
c3=Computer()

#call function by objects
c1.function()
c2.function()
c3.function()

#delete object
del(c1)
del(c2)
del(c3)


output-

Object is created
Object is created
Object is created
Function is called
Function is called
Function is called


-In this program, we delete all object of the classes
-If we again use deleted object then?

program-

c1.function()


output-

c1.function()
NameError: name 'c1' is not defined




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!