IPython - History Command



IPython preserves both the commands and their results of the current session. We can scroll through the previous commands by pressing the up and down keys.

Besides, last three objects of output are stored in special variables _, __ and ___. The history magic command shows previous commands in current session as shown in the examples given below −

Usage of history command

In [10]: history
2 + 2
print("Hello")
x = 2
x
x = "hello"
x?
run main.py
edit main.py
edit
history

In [11]:

Usage of _ Special Variable

In [11]: _
Out[11]: 'print ("magic of IPython")'

Usage of __ Special Variable

In [11]: __
Out[11]: 'print ("magic of IPython")'

Usage of ___ Special Variable

In [11]: ___
Out[11]: 'print ("magic of IPython")'
Advertisements