Chapters:
Synkoc AI/ML Internship · Week 1 · Lesson 1 of 13
Python for
AI & Machine Learning
Master the complete Python foundation — Variables, Loops, Functions & Data Structures. Every concept connects directly to real ML code.
📦 Variables
🔁 Loops
⚙️ Functions
🗂️ Data Structures
🧑‍💻
Synkoc Instructor
AI/ML Professional · Bangalore
⏱ ~60 minutes
🟢 Beginner Friendly
By the end of this lesson, you will be able to...
📦
Create & use Variables
Store any data type. Understand why every ML model's weights, accuracy and labels are stored in variables.
🔁
Write Loops that process data
Iterate over entire datasets automatically. Understand how ML training loops over every example in every epoch.
⚙️
Build reusable Functions
Write clean, reusable logic with def & return. Every sklearn algorithm is a function you call with data.
🗂️
Organise with Data Structures
Use Lists, Dicts, Tuples, Sets. Direct predecessors to NumPy arrays and Pandas DataFrames in Week 2.
Chapter 1 of 4
01
Variables
The most fundamental concept in all of programming. Every ML model's weights, accuracy, and labels live in variables.
What is a Variable?
A variable is a named container that stores a value in memory. Give it a name, assign a value — Python handles the rest.
📦
name = value
The equals sign means assignment — store the right-side value under the left-side name. Any time Python sees that name, it retrieves the stored value from memory. You can reassign any time.
student_name = "Priya"    # String — text in quotes
exam_score   = 94.5      # Float — decimal number
batch_size   = 32        # Integer — whole number
is_trained   = False      # Boolean — True or False
ML Connection: learning_rate = 0.001 · epochs = 100 · accuracy = 0.956 · model_name = "RandomForest" — every ML project config lives in variables exactly like these.
The 4 Core Data Types
Python auto-detects type from the value you assign. These 4 types cover 95% of everything you store in an ML project:
🔢
Integer (int)
Whole numbers. For epoch counts, batch sizes, neuron counts, tree counts.
epochs = 100
batch_size = 32
n_trees = 200
ML: epochs, layers, trees
📏
Float (float)
Decimals. For accuracy %, learning rates, model weights, probabilities.
accuracy = 0.956
lr = 0.001
dropout = 0.2
ML: accuracy, loss, weights
📝
String (str)
Text in quotes. For class labels, file paths, feature names, model names.
label = "spam"
file = "data.csv"
model = "SVM"
ML: labels, paths, names
Boolean (bool)
True or False only. For flags, conditions, binary classification outputs.
verbose = True
is_trained = False
use_gpu = True
ML: flags, binary outputs
variables_demo.py● LIVE
Variables in Real ML Projects
Every professional ML project starts with a config block. Every setting has a descriptive variable name — change one variable to update the entire project.
ml_project_config.py
1# ── Project Config ──────────────────────────────
2project_name = "Synkoc Student Pass/Fail Predictor"
3dataset_path = "data/students.csv"
4target_col = "passed"    # What we are predicting
5 
6# ── Model Hyperparameters ───────────────────────
7learning_rate = 0.001    # How fast the model learns
8epochs = 100      # Training rounds
9test_size = 0.2      # 20% held back for testing
10random_state = 42       # Seed for reproducibility
11verbose = True      # Print training progress
💡
Professional Tip
Always use descriptive names like learning_rate not just lr. Change one variable → entire project updates. Every ML team at every company follows this pattern.
Chapter 2 of 4
02
Loops
Repeat actions over data without writing the same code thousands of times. The engine behind every ML training process ever built.
What is a Loop?
A loop says: "For every item in this collection — do this action." Write your logic once. Python repeats it automatically for every item.
🔁
for item in collection:
Three parts: the for keyword, a variable name that holds the current item, and the collection. Colon ends the line. Indented code below runs once per item — automatically, for every item, start to end.
scores = [78, 92, 65, 88, 71]

for score in scores:
    print(f"Processing: {score}")

# Visits: 78 → 92 → 65 → 88 → 71
ML Connection: Training on 10,000 records × 50 epochs = 500,000 loop iterations. The for loop handles every single one automatically — you write the logic once.
loops_demo.py● LIVE
The Loop Analogy
Synkoc Instructor Analogy
"Imagine a Synkoc instructor marking 30 exam papers. She picks up paper 1, grades it, puts it down. Paper 2 — same process. Paper 3 — same. She repeats the identical action for every paper until done. That is a for loop. The pile of papers is your list. Each paper is one item. The grading action is your loop body. Python is the instructor — infinitely patient, never skipping, completing every iteration without mistakes."
🤖
In Real ML Training
10,000 records × 100 epochs = 1,000,000 iterations. The for loop — the exact same one you are learning right now — handles all of it. TensorFlow and PyTorch training loops are built on this exact concept.
Chapter 3 of 4
03
Functions
Write code once, use it a thousand times. Every sklearn algorithm — LinearRegression, KMeans, RandomForest — is a function you call with your data.
What is a Function?
A function is a named, reusable block of code. Define once with def. Call from anywhere with any data. return sends the result back.
⚙️
def function_name(parameters):
Four parts: def starts it, a descriptive name, parameters (placeholder names for inputs), and return. Call it by writing the name with actual values — called arguments.
def calculate_accuracy(correct, total):
    return (correct / total) * 100

result = calculate_accuracy(87, 100)
print(f"Accuracy: {result}%")  # → 87.0%
ML Connection: model.fit(X, y) · model.predict(X_test) · accuracy_score(y_true, y_pred) — you already call functions every time you use sklearn. Now you write your own.
functions_demo.py● LIVE
Chapter 4 of 4
04
Data Structures
Organise collections of data — the containers that hold your entire dataset before feeding it into any ML model.
The 4 Core Data Structures
When a single variable is not enough, use a structure. These 4 are the direct foundation of NumPy arrays and Pandas DataFrames in Week 2:
📋
List [ ]
Ordered, changeable, allows duplicates. Access by index from 0. The most-used structure in all of data science.
scores = [85, 92, 78, 96]
labels = ["pass","fail","pass"]
🗂️
Dictionary { key: value }
Key-value pairs — access by name. One dictionary = one complete row of your ML dataset with feature names mapped to values.
student = {"name":"Rahul",
  "score":91, "passed":True}
🔒
Tuple ( )
Like a list but immutable — cannot be changed. Use for fixed shapes and configs that must never be accidentally modified.
img_shape = (224, 224, 3)
split_ratio = (0.8, 0.2)
Set { }
Unordered, unique values only — duplicates auto-removed. Pass 10,000 labels in, get only unique class names back.
classes = {"cat","dog","bird"}
unique = set(all_labels)
data_structures_demo.py● LIVE
All 4 Pillars Together — Complete Program
student_analyzer.pyComplete Program
1# DATA STRUCTURE — list of dicts, one per student
2students = [{"name":"Priya", "scores":[85,92,78,96]},
3            {"name":"Rahul", "scores":[70,65,80,75]},
4            {"name":"Anjali","scores":[95,98,92,97]}]
5 
6# FUNCTION — takes any list, returns average
7def compute_average(scores):
8    return sum(scores) / len(scores)
9 
10# LOOP — process every student automatically
11for s in students:
12    name = s["name"]               # VARIABLE
13    avg = compute_average(s["scores"])  # FUNCTION CALL
14    print(f"{name}: Average = {avg:.1f}")
This program uses all 4 pillars: a list of dicts holds the data · a function computes averages · a loop processes every student · variables store name and avg. This is the exact pattern used in real ML data pipelines.
Lesson Summary
You have completed the Python foundation. Here is what you can now do in every ML project:
📦
Variables
Store any data type with a meaningful name. Configure ML projects professionally. Know int, float, str, bool and when to use each.
🔁
Loops
Iterate over any list with a for loop. Combine with if/else. Understand that ML training is a massive nested loop over data and epochs.
⚙️
Functions
Define reusable logic with def and return. Use parameters and defaults. Understand that every sklearn call is a function like the ones you now write.
🗂️
Data Structures
Use Lists, Dicts, Tuples, Sets. These are the direct foundation of NumPy arrays and Pandas DataFrames you will use in Week 2.
🚀
Python Complete!
Foundation mastered. Open the Practical Lab to write real code across 5 tasks. Complete the lab, then take the Quiz. Then — Statistics for Data Science.
✅ Video — Done
✏️ Practical Lab — Next
❓ Quiz — After Lab
Synkoc IT Services · Bangalore · [email protected] · +91-9019532023
Press ▶ Play to start the lesson with voice narration
0:00 / ~60:00
🔊
1 / 20