Learn GOOGLE-COLAB with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World in Google Colab (Python)
print("Hello World")
A simple Python cell in Google Colab printing 'Hello World'.
2
Simple TensorFlow in Google Colab
import tensorflow as tf
hello = tf.constant("Hello Colab!")
print(hello.numpy().decode("utf-8"))
Using TensorFlow in Colab to create a basic constant and run it.
3
NumPy Array Example in Colab
import numpy as np
arr = np.array([[1,2,3],[4,5,6]])
print(arr.shape)
Create a NumPy array and print its shape.
4
Matplotlib Plot in Colab
import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [10,20,25,30]
plt.plot(x,y)
plt.title('Line Graph')
plt.show()
Plot a simple line graph using matplotlib.
5
Pandas DataFrame Example in Colab
import pandas as pd
data = {'Name':['Alice','Bob'],'Age':[25,30]}
df = pd.DataFrame(data)
df
Create a Pandas DataFrame and display it.
6
Seaborn Plot Example in Colab
import seaborn as sns
import numpy as np
import pandas as pd
data = pd.DataFrame({'x': np.random.rand(50), 'y': np.random.rand(50)})
sns.scatterplot(x='x', y='y', data=data)
Create a Seaborn scatter plot with random data.
7
Interactive Widgets in Colab
from ipywidgets import IntSlider
slider = IntSlider(value=5, min=0, max=10, step=1)
slider
Create a simple slider widget using ipywidgets.
8
PyTorch Tensor Example in Colab
import torch
tensor = torch.randn(3,3)
print(tensor.shape)
Create a tensor in PyTorch and print its shape.
9
Markdown Cell Example in Colab
# Hello Colab
This is a **Markdown** cell in Google Colab.
A Markdown cell displaying formatted text.
10
SymPy Symbolic Math in Colab
from sympy import symbols, expand
x, y = symbols('x y')
expr = (x + y)**2
expand(expr)
Define symbols and perform symbolic math using SymPy.