How to clear variable in python
Python
Mohit Mozumder
Solution:
To clear variable in python you can use del function -just write-
del variable
for multiple variable -
del variable1, variable2, variable3
Note: The del
statement removes the variable from the namespace,
but it does not clear it from memory. We can use gc.collect()
method after del function to clear the variable from memory.
import numpy as np
import gc
a = np.array([1,2,3])
del a
gc.collect()
or-
You can clear variables by using %reset-f function.
%reset-f
-f
does the force action on the given command without prompting for yes/no.
You can also use only
%reset
Thank you for reading the article. If you still face any problem feel free to contact with us.