How to clear variables in ipython? How to clear variables in ipython? python python

How to clear variables in ipython?


%reset seems to clear defined variables.


EDITED after @ErdemKAYA comment.

To erase a variable, use the magic command:

%reset_selective <regular_expression>

The variables that are erased from the namespace are the one matching the given <regular_expression>.

Therefore

%reset_selective -f a 

will erase all the variables containing an a.

Instead, to erase only a and not aa:

In: a, aa = 1, 2In: %reset_selective -f "^a$"In: a  # raise NameErrorIn: aa  # returns 2

see as well %reset_selective? for more examples and https://regexone.com/ for a regex tutorial.

To erase all the variables in the namespace see:

%reset?


In iPython you can remove a single variable like this:

del x