IPython
- IPython - Introduction
- IPython - Installation
- IPython - Getting Started
- Running & Editing Python Script
- IPython - History Command
- IPython - System Commands
- IPython - Command Line Options
- Dynamic Object Introspection
- IPython - IO Caching
- Setting IPython as Default Python Environment
- Importing Python Shell Code
- IPython - Embedding IPython
- IPython - Magic Commands
Jupyter
- Project Jupyter - Overview
- Jupyter Notebook - Introduction
- Working With Jupyter Online
- Installation and Getting Started
- Jupyter Notebook - Dashboard
- Jupyter Notebook - User Interface
- Jupyter Notebook - Types of Cells
- Jupyter Notebook - Editing
- Jupyter Notebook - Markdown Cells
- Cell Magic Functions
- Jupyter Notebook - Plotting
- Converting Notebooks
- Jupyter Notebook - IPyWidgets
QtConsole
- QtConsole - Getting Started
- QtConsole - Multiline Editing
- QtConsole - Inline Graphics
- QtConsole - Save to Html
- QtConsole - Multiple Consoles
- Connecting to Jupyter Notebook
- Using github and nbviewer
JupyterLab
- JupyterLab - Overview
- Installation & Getting Started
- JupyterLab - Interface
- JupyterLab - Installing R Kernel
Jupyter Resources
IPython - IO Caching
The input and output cells on IPython console are numbered incrementally. In this chapter, let us look into IO caching in Python in detail.
In IPython, inputs are retrieved using up arrow key. Besides, all previous inputs are saved and can be retrieved. The variables _i, __i, and ___i always store the previous three input entries. In addition, In and _in variables provides lists of all inputs. Obviously _in[n] retrieves input from nth input cell. The following IPython session helps you to understand this phenomenon −
Example - Using _i, __i, ___i
In [1]: print ("Hello")
Hello
In [2]: 2+2
Out[2]: 4
In [3]: x = 10
In [4]: y = 2
In [5]: pow(x,y)
Out[5]: 100
In [6]: _iii, _ii, _i
Out[6]: ('x = 10', 'y = 2', 'pow(x,y)')
In [7]: In
Out[7]:
['',
'print ("Hello")',
'2+2',
'x = 10',
'y = 2',
'pow(x,y)',
'_iii, _ii, _i',
'In'
]
In [8]: In[5] 9. IPython IO
Out[8]: 'pow(x,y)'
In [9]: _ih
Out[9]:
['',
'print ("Hello")',
'2+2',
'x = 10',
'y = 2',
'pow(x,y)',
'_iii, _ii, _i',
'In',
'In[5]',
'_ih'
]
In [11]: _ih[4]
Out[11]: 'y = 2'
In [12]: In[1:4]
Out[12]: ['print ("Hello")', '2+2', 'x=10']
Example - Using _, __, ___
Similarly, single, double and triple underscores act as variables to store previous three outputs. Also Out and _oh form a dictionary object of cell number and output of cells performing action (not including assignment statements). To retrieve contents of specific output cell, use Out[n] or _oh[n]. You can also use slicing to get output cells within a range.
In [1]: print ("Hello")
Hello
In [2]: 2+2
Out[2]: 4
In [3]: x = 10
In [4]: y = 3
In [5]: pow(x,y)
Out[5]: 1000
In [6]: ___, __, _
Out[6]: ('', 4, 1000)
In [7]: Out
Out[7]: {2: 4, 5: 1000, 6: ('', 4, 1000)}
In [8]: _oh
Out[8]: {2: 4, 5: 1000, 6: ('', 4, 1000)}
In [9]: _5
Out[9]: 1000
In [10]: Out[6]
Out[10]: ('', 4, 1000)