Functions

Mon 30 June 2025
def greet():
    print("Hello, Sara!")

greet()
Hello, Sara!
def add(a, b):
    return a + b
add(5, 3)
8
def say_hello():
    print("Hello!")
def greet_name(name):
    print(f"Hi {name}!")
def square(x):
    return x * x
def welcome(name="Sara"):
    print(f"Welcome, {name}!")
def intro(name, age):
    print(f …

Category: basics

Read More

Hashtables

Mon 30 June 2025
d = {}
d['a'] = 1
d['b'] = 2
print(d)
{'a': 1, 'b': 2}
print(d['a'])
1
d['c'] = 3
d['a'] = 100
print(d)
{'a': 100, 'b': 2, 'c': 3}
del d['b']
print(d)
{'a': 100, 'c': 3}
len(d)
2
d.get('a')
100
d.get('z …

Category: basics

Read More

Html Css Basics

Mon 30 June 2025
# Cell 1 - HTML Example
from IPython.display import display, HTML


html_content_1 = """
<!DOCTYPE html>
<html>
<head>
    <title>HTML Cell 1</title>
</head>
<body>
    <h1>HTML Practice Cell 1</h1>
    <p>This is unique content for HTML cell 1.</p>
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3 …

Category: basics

Read More

Iris Knn Classifier

Mon 30 June 2025
from sklearn.datasets import load_iris
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = KNeighborsClassifier(n_neighbors=3)
model.fit(X_train, y_train)

Category: basics

Read More

Itertools

Mon 30 June 2025
import itertools
list(itertools.count(10, 2))[:11]
list(itertools.cycle('ABCD'))[:12]
list(itertools.repeat('hello', 5))
list(itertools.accumulate([1,2,3,4]))
list(itertools.chain('ABC', 'DEF'))
list(itertools.compress('ABCDEF', [1,0,1,0,1,0]))
list(itertools.dropwhile(lambda x: x<5, [1,4,6 …

Category: basics

Read More

Lambda Map Filter Reduce

Mon 30 June 2025
x = [1, 2, 3]
y = ['a', 'b', 'c']
z = zip(x, y)
print(list(z))
[(1, 'a'), (2, 'b'), (3, 'c')]
x = lambda a, b, c : a + b + c
print(x(1, 2, 3))
6
nums = [1, 2, 3, 4, 5, 6]
result = list(filter(lambda x: x % 2 == 0 …

Category: basics

Read More

List Vs Tuple

Mon 30 June 2025
import time
list1 = [1, 2, 3]
list1[0] = 100
tuple1 = (1, 2, 3)
try:
    tuple1[0] = 100
except TypeError as e:
    print("Tuples are immutable:", e)
Tuples are immutable: 'tuple' object does not support item assignment
def list_test():
    list_x = [x for x in range(1000000)]

def tuple_test():
    tuple_x = tuple(x …

Category: basics

Read More

Loops And Conditions

Mon 30 June 2025
for i in range(1, 6):
    print(f"Square of {i} is {i**2}")
Square of 1 is 1
Square of 2 is 4
Square of 3 is 9
Square of 4 is 16
Square of 5 is 25
n = 5
while n > 0:
    if n % 2 == 0:
        print(n …

Category: basics

Read More

Matplotlib Demo

Mon 30 June 2025
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [5, 7, 4, 6, 8]
plt.plot(x, y, marker='o')
plt.title("Line Plot")
plt.xlabel("X")
plt.ylabel("Y")
plt.grid(True)
plt.show()

png

names = ["A", "B", "C"]
scores = [75, 88, 92]
plt.bar(names, scores …

Category: basics

Read More

Numpy Basics

Mon 30 June 2025
import numpy as np
a = np.array([1, 2, 3])
b = np.array([[1, 2], [3, 4]])
print("1D array:", a)
print("2D array:\n", b)
1D array: [1 2 3]
2D array:
 [[1 2]
 [3 4]]
print("Sum:", a.sum())
print("Mean:", a.mean())
print("Max:", a …

Category: basics

Read More
Page 2 of 4

« Prev Next »