2. Notebook Document Layout & Cells
The Notebook Document Structure
A Jupyter Notebook is saved as an .ipynb file, which is essentially a JSON-formatted document containing metadata and a sequence of cells. Each cell serves as the building block for the document, allowing for a mix of executable code, descriptive documentation, and raw output data.
.ipynb structure updates dynamically.
Understanding Cell States
Notebooks utilize three primary cell types: 'Code cells', which contain logic executed by the kernel; 'Markdown cells', used for documentation; and 'Raw NBConvert cells', which remain unformatted during exports. You can toggle these states using the toolbar or specific shortcuts.
When executing code, you will see an 'In [*]' indicator; the asterisk implies the kernel is actively processing. Once finished, it changes to 'In [n]', where n denotes the sequential order of execution.
import time # This cell acts as a simulation of code execution # The kernel status will briefly show an asterisk during sleep time.sleep(2) print('Execution complete')
Navigation and Modes
Jupyter interfaces rely on two distinct interaction modes. 'Command mode' (indicated by a blue left border) allows you to perform operations on the cell structure itself, such as adding or deleting cells. 'Edit mode' (indicated by a green left border) allows you to modify the content within a cell.
Press Esc to enter Command mode and Enter to switch to Edit mode. Efficient navigation relies on these shortcuts to maintain high productivity.
A or B while in Command mode to insert a cell above or below your current position, respectively.
Knowledge Check
Ready to test your understanding of 2. Notebook Document Layout & Cells?