Introduction to Jupyter Notebook
Jupyter Notebook is a web-based interactive computing environment that integrates code execution, documentation, and visualization. It supports live coding, mathematical equations, narrative text, and rich media output within a single document.
Core Components
- Web Application: Provides an interface for authoring and executing documents containing code, equations, and visualizations.
- Notebook Documents: Combines executable code, equations, visualizations, and explanatory text in a shareable format.
Key Features
- Syntax highlighting and code completion
- Inline code execution with immediate output
- Markdown support for documentation
Installing Jupyter Notebook
Prerequisites
- Python 2.7 or Python 3.3+
Installation Methods
Via Anaconda (Recommended for Beginners)
Anaconda includes Jupyter Notebook and over 180 scientific packages. Install Anaconda from its ofifcial site. If already installed, verify or add Jupyter with:
conda install jupyter
Using pip
- Upgrade pip:
# Python 3 pip3 install --upgrade pip # Python 2 pip install --upgrade pip - Install Jupyter:
# Python 3 pip3 install jupyter # Python 2 pip install jupyter
Launching Jupyter Notebook
Basic Commands
- Start server:
jupyter notebook - Access via browser at
http://localhost:8888
Advanced Options
- Custom port:
jupyter notebook --port 9999 - Headless mode (no browser):
Copy the generated URL to access later.jupyter notebook --no-browser
Keyboard Shortcuts
| Action | Shortcut |
|---|---|
| Add cell above | a |
| Add cell below | b |
| Delete cell | x |
| Convert to Markdown | m |
| Convert to Code | y |
| Execute cell | Shift+Enter |
| View docs | Shift+Tab |
| Auto-complete | Tab |
Magic Commands
- Execute external script:
%run script.py - Time execution:
%time statement - Measure average runtime:
%timeit statement - Time multi-line blocks:
%%timeit line1 line2