
- Jupyter 教程
- Jupyter - 首頁
- IPython
- IPython - 簡介
- IPython - 安裝
- IPython - 入門
- 執行和編輯 Python 指令碼
- IPython - 歷史命令
- IPython - 系統命令
- IPython - 命令列選項
- 動態物件自省
- IPython - IO 快取
- 將 IPython 設定為預設 Python 環境
- 匯入 Python Shell 程式碼
- IPython - 嵌入 IPython
- IPython - 魔法命令
- Jupyter
- Project Jupyter - 概述
- Jupyter Notebook - 簡介
- 使用線上 Jupyter
- 安裝和入門
- Jupyter Notebook - 儀表盤
- Jupyter Notebook - 使用者介面
- Jupyter Notebook - 單元格型別
- Jupyter Notebook - 編輯
- Jupyter Notebook - Markdown 單元格
- 單元格魔法函式
- Jupyter Notebook - 繪圖
- 轉換筆記本
- Jupyter Notebook - IPyWidgets
- QtConsole
- QtConsole - 入門
- QtConsole - 多行編輯
- QtConsole - 內聯圖形
- QtConsole - 儲存為 Html
- QtConsole - 多個控制檯
- 連線到 Jupyter Notebook
- 使用 github 和 nbviewer
- JupyterLab
- JupyterLab - 概述
- 安裝和入門
- JupyterLab - 介面
- JupyterLab - 安裝 R 核心
- Jupyter 資源
- Jupyter - 快速指南
- Jupyter - 有用資源
- Jupyter - 討論
IPython - IO 快取
IPython 控制檯上的輸入和輸出單元格按順序遞增編號。在本章中,讓我們詳細瞭解一下 Python 中的 IO 快取。
在 IPython 中,可以使用向上箭頭鍵檢索輸入。此外,所有以前的輸入都會被儲存並可以檢索。變數_i、__i 和___i始終儲存前三個輸入條目。此外,In 和_in 變數提供了所有輸入的列表。顯然,_in[n] 從第 n 個輸入單元格檢索輸入。以下 IPython 會話可以幫助您理解這種現象:
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']
類似地,單下劃線、雙下劃線和三下劃線充當變數以儲存前三個輸出。此外,Out 和_oh 形成了一個字典物件,其中包含執行操作(不包括賦值語句)的單元格的單元格編號和輸出。要檢索特定輸出單元格的內容,請使用Out[n] 或_oh[n]。您還可以使用切片獲取一定範圍內的輸出單元格。
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)
廣告