Articles → Python → Del Method In Python For Deleting Module From Default Namespace

Del Method In Python For Deleting Module From Default Namespace






Purpose




Picture showing the del method for deleting the module from default namespace in python

Click to Enlarge



  1. Math module is imported using import keyword. Math module is added in default namespace.
  2. Print the value of math.pi.
  3. Delete the module using del() method.
  4. Print the value of math.pi. This time, code will give an error as math module is removed from default namespace.

Using Del For Variables




temp = "This is temp variable"

# Print
print(temp)

#Delete
del(temp)

# Print (This method will give error)
print(temp)




Picture showing the del method to delete the variable in python

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, April 16, 2019
 
Updated On  -  Wednesday, May 15, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250