```html
``` Skip to contentWhen learning Python, Data Science, Artificial Intelligence (AI), or Machine Learning (ML), one of the first questions beginners ask is, “Where should I write and run Python code?” Two of the most popular tools are Jupyter Notebook and Google Colab. Both provide an interactive environment where you can write Python code, execute it step by step, visualize data, and document your work—all in a single notebook.
Unlike traditional programming environments where code is written inside plain text files, Jupyter Notebook and Google Colab organize your work into cells. These cells can contain executable Python code, formatted text, mathematical equations, tables, images, and charts. This interactive approach makes learning programming much easier because you can immediately see the output of each code block.
Today, millions of students, researchers, data scientists, Machine Learning engineers, and AI developers use Jupyter Notebook and Google Colab for data analysis, model training, research, experimentation, and education. Companies such as Google, Microsoft, IBM, Amazon, Meta, Netflix, and many universities use notebook-based environments because they simplify experimentation and collaboration.
Jupyter Notebook is a free, open-source web application that allows users to create and share interactive notebooks containing live code, equations, visualizations, charts, and explanatory text. It supports dozens of programming languages, although Python is the most commonly used language within Jupyter.
The name Jupyter comes from the three programming languages it originally supported:
Today, Jupyter supports more than 40 programming languages through different kernels, making it one of the most flexible development environments for scientific computing and Machine Learning.
Jupyter Notebook originated from the IPython project, which was created by Fernando Pérez in 2001. The goal was to provide an interactive computing environment where programmers could experiment with Python code more efficiently than using the traditional command-line interpreter.
As the project evolved, support for additional programming languages was added, and the Jupyter Project was officially launched in 2014. Since then, Jupyter Notebook has become one of the most widely used tools in Data Science, Artificial Intelligence, academic research, and engineering.
Jupyter Notebook combines programming, documentation, visualization, and experimentation into a single interface. Instead of switching between multiple applications, users can perform every stage of data analysis inside one notebook.
Some major advantages include:
Google Colaboratory, commonly called Google Colab, is Google’s cloud-based notebook platform built on Jupyter Notebook. It allows users to write and execute Python code directly in a web browser without installing Python, Jupyter, or any additional software.
Since everything runs on Google’s cloud servers, beginners can start learning Machine Learning immediately without worrying about software installation, operating system compatibility, or hardware limitations.
Google Colab integrates seamlessly with Google Drive, making it easy to save notebooks, share projects, and collaborate with classmates or colleagues in real time.
Google introduced Colab to make Machine Learning education and research more accessible. Many beginners struggle to install Python libraries, configure development environments, or obtain powerful computers capable of training Machine Learning models.
Google Colab solves these problems by providing:
A Jupyter Notebook consists of multiple cells. Each cell performs a specific function and can be executed independently.
| Cell Type | Purpose |
|---|---|
| Code Cell | Run Python code. |
| Markdown Cell | Write formatted text. |
| Raw Cell | Store plain text. |
| Output Cell | Displays execution results. |
This structure makes notebooks ideal for explaining concepts while simultaneously demonstrating Python code and displaying outputs.
| Feature | Jupyter Notebook | Google Colab |
|---|---|---|
| Installation | Required | No Installation |
| Runs On | Local Computer | Cloud |
| GPU Support | Depends on Your Hardware | Free GPU Available |
| Internet Required | No | Yes |
| Sharing | Manual | One Click |
| Best For | Offline Development | Learning & Collaboration |
In the next part, you will learn how to install Jupyter Notebook, create your first notebook, use code cells and Markdown cells, execute Python programs, install packages, and use essential keyboard shortcuts for faster development.
Before you can use Jupyter Notebook, you need to install Python and Jupyter on your computer. The easiest way to do this is by installing the Anaconda Distribution, which comes with Python, Jupyter Notebook, JupyterLab, Spyder, and many popular Data Science libraries already installed.
Alternatively, you can install Jupyter Notebook using the Python package manager (pip) if Python is already installed on your computer.
Open Command Prompt or Terminal and run the following command:
pip install notebook
To verify the installation:
jupyter --version
After installation, start Jupyter Notebook using the following command:
jupyter notebook
This command launches a local Jupyter server and automatically opens your default web browser with the Jupyter Notebook dashboard.
The dashboard is the home screen of Jupyter Notebook. From here you can:
A notebook is divided into independent cells. Each cell can contain code or formatted documentation.
| Cell Type | Purpose |
|---|---|
| Code Cell | Execute Python code. |
| Markdown Cell | Write formatted documentation. |
| Raw Cell | Store plain text. |
Create a new code cell and type:
print("Hello, Machine Learning!")
Output
Hello, Machine Learning!
Press Shift + Enter to execute the cell.
Markdown cells allow you to write documentation alongside your code. You can create headings, lists, tables, images, links, and mathematical equations.
# Machine Learning
## Python Basics
This notebook explains Python fundamentals.
Notebook cells execute independently. Variables created in one cell remain available to later cells until the kernel is restarted.
Cell 1
x = 50
Cell 2
print(x)
Output
50
The kernel is the Python engine that executes notebook code. Restarting the kernel clears all variables and memory.
Restart the kernel when:
Jupyter automatically saves notebooks periodically, but you can manually save by:
Notebook files are stored with the .ipynb extension.
Sometimes additional Python libraries are required.
pip install pandas
Or directly inside a notebook:
!pip install pandas
Most Machine Learning notebooks begin by importing required libraries.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Jupyter provides special commands called Magic Commands that simplify notebook operations.
| Command | Purpose |
|---|---|
| %time | Measure execution time. |
| %pwd | Show current directory. |
| %ls | List files. |
| %who | Display variables. |
| %%time | Measure entire cell execution time. |
%time
sum(range(1000000))
| Shortcut | Action |
|---|---|
| Shift + Enter | Run current cell. |
| Ctrl + Enter | Run cell without moving. |
| Alt + Enter | Run cell and create a new one. |
| A | Insert cell above. |
| B | Insert cell below. |
| DD | Delete selected cell. |
| M | Convert to Markdown. |
| Y | Convert to Code. |
| Error | Reason | Solution |
|---|---|---|
| ModuleNotFoundError | Package missing | Install using pip |
| NameError | Variable not defined | Run previous cell |
| IndentationError | Incorrect spacing | Fix indentation |
| SyntaxError | Incorrect Python syntax | Correct the code |
In the next part, you will learn how to use Google Colab, including Google Drive integration, uploading datasets, enabling GPU and TPU, installing libraries, sharing notebooks, and collaborating on Machine Learning projects.
Google Colab (Google Colaboratory) is a free cloud-based notebook environment developed by Google for Python programming, Data Science, Artificial Intelligence, and Machine Learning. It is built on the Jupyter Notebook interface, allowing users to write and execute Python code directly in a web browser without installing any software.
One of the biggest advantages of Google Colab is that it comes with Python and many popular Machine Learning libraries already installed. Beginners can start coding immediately without worrying about installing Python, configuring environments, or managing dependencies.
Google Colab is especially useful for students, educators, and professionals who want a simple and powerful environment for Machine Learning development.
Type the following code into the first code cell.
print("Welcome to Google Colab!")
Output
Welcome to Google Colab!
Click the Run button or press Shift + Enter to execute the code.
Many Machine Learning projects require datasets stored as CSV, Excel, or text files. Google Colab allows you to upload files directly from your computer.
from google.colab import files
uploaded = files.upload()
After running the code, a file selection dialog appears, allowing you to upload datasets from your local computer.
import pandas as pd
df = pd.read_csv("students.csv")
print(df.head())
The head() function displays the first five rows of the dataset.
Instead of uploading files every time, you can connect Google Drive to Google Colab. This allows notebooks to access datasets stored permanently in your Drive.
from google.colab import drive
drive.mount('/content/drive')
After authorizing your Google account, Drive becomes accessible inside Colab.
import pandas as pd
df = pd.read_csv('/content/drive/MyDrive/Datasets/students.csv')
print(df.head())
Although Google Colab includes many popular libraries, you may occasionally need additional packages.
!pip install plotly
The exclamation mark (!) allows shell commands to run directly inside notebook cells.
!pip list
Machine Learning and Deep Learning models often require significant computing power. Google Colab provides free access to Graphics Processing Units (GPUs), which can dramatically reduce model training time.
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))
Tensor Processing Units (TPUs) are specialized processors developed by Google for Deep Learning workloads. TPUs can train large neural networks much faster than CPUs.
Most Machine Learning notebooks begin by importing essential Python libraries.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [5,8,4,9,7]
plt.plot(x,y)
plt.show()
Charts appear immediately below the code cell.
Google Colab allows multiple users to collaborate on the same notebook, similar to Google Docs.
To share a notebook:
You can export notebooks in multiple formats.
| Feature | Free | Colab Pro |
|---|---|---|
| CPU | Yes | Yes |
| GPU | Limited | Faster GPU |
| TPU | Limited | More Availability |
| RAM | Standard | High RAM |
| Runtime Duration | Limited | Longer Sessions |
| Feature | Jupyter Notebook | Google Colab |
|---|---|---|
| Installation | Required | No Installation |
| Internet | Not Required | Required |
| Runs On | Local Computer | Cloud Server |
| GPU Support | Depends on Hardware | Free GPU Available |
| Automatic Saving | No | Yes |
| Collaboration | Limited | Excellent |
| Best For | Offline Development | Learning and Team Collaboration |
Google Colab provides an easy-to-use cloud environment for Python programming and Machine Learning. It eliminates software installation, offers free GPU and TPU resources, integrates seamlessly with Google Drive, and supports collaboration through shared notebooks. Together with Jupyter Notebook, Google Colab has become one of the most widely used platforms for Data Science, Artificial Intelligence, and Machine Learning education. Beginners can quickly experiment with Python code, analyze datasets, visualize data, and train Machine Learning models directly from their web browser.
Yes. Google Colab offers a free version with access to CPUs, limited GPUs, and TPUs. Paid plans such as Colab Pro provide faster hardware, more memory, and longer runtime sessions.
No. Google Colab runs entirely in the browser and includes Python along with many popular Data Science and Machine Learning libraries.
No. Google Colab is a cloud-based service and requires an internet connection to access notebooks and execute code.
Google Colab is generally the better choice for beginners because it requires no installation, includes pre-installed libraries, and provides free cloud computing resources. Jupyter Notebook is better suited for offline development and users who prefer working on their local computer.
In the next lesson, you will learn NumPy for Machine Learning, including arrays, indexing, slicing, broadcasting, vectorized operations, mathematical functions, random number generation, and performance optimization for scientific computing.