🟢 Day 3 — Working With Many Values (Lists & Strings)
1️⃣ Why Do We Need This?
Until now, we worked like this:
Real-life problem
What if:
You have marks of 50 students You have prices of 100 products You have names of 1000 users Creating separate variables is:
💡 When you have many similar values, you use a collection.
2️⃣ Introducing Lists — One Variable, Many Values
Real-world analogy
Think of a train:
Many compartments (elements) Each compartment has a number (index) Creating a List
numbers = [10, 20, 30, 40]
Here:
10, 20, 30, 40 → elements 3️⃣ Indexing — How to Access Elements
print(numbers[0]) # 10
print(numbers[1]) # 20
Important Rule (VERY IMPORTANT)
Python starts counting from 0, not 1.
Index: 0 1 2 3
Value: 10 20 30 40
Why Index Starts From 0?
You don’t need to memorize why, just accept:
Index = how far from the start
First element is 0 steps away.
4️⃣ What Happens If Index Does Not Exist?
❌ Program crashes.
Why?
It only accesses what exists 🧠 The computer never assumes.
It either finds something or fails.
5️⃣ Looping Over a List (MOST USED PATTERN)
Instead of accessing elements one by one:
print(numbers[0])
print(numbers[1])
Use a loop:
for num in numbers:
print(num)
How Computer Thinks
6️⃣ Lists + Logic = Real Programs
Example: Find Largest Number
numbers = [10, 45, 23, 89, 5]
largest = numbers[0]
for num in numbers:
if num > largest:
largest = num
print(largest)
How to Think (THIS IS IMPORTANT)
Assume first number is largest Update when you find bigger 🧠 This thinking pattern is used everywhere in programming.
7️⃣ Strings Are Also Collections 🤯
You already know strings:
But a string is actually:
Looping Over String
for ch in name:
print(ch)
💡 Strings behave like lists of characters.
8️⃣ Length of List or String
print(len(numbers))
print(len(name))
len() tells how many items Works for list and string 9️⃣ Counting Pattern (Extremely Important)
Example: Count Even Numbers
count = 0
for num in numbers:
if num % 2 == 0:
count += 1
print(count)
Thinking Pattern
Increase when condition matches 🧠 Counting is one of the most used patterns in programming.
🔁 Key Thinking Patterns Learned Today
Whenever you see a collection, ask:
Do I need to check every element? Do I need to remember something while looping? Do I need to compare values? Do I need to count or accumulate? ⚠️ Common Beginner Mistakes
Modifying list incorrectly Confusing index and value Assuming list has unlimited size 🧪 Practice Questions (Very Important)
Do not rush.
Think → write steps → then code.
Q1
Create a list of 5 numbers and print all elements.
Q2
Find the smallest number in a list.
Q3
Count how many even numbers are in a list.
Q4
Check if a given number exists in a list.
Example:
List: [1, 2, 3, 4]
Input: 3
Output: Found
Q5
Reverse a list without using built-in reverse.
Q6
Count number of vowels in a string.
Example:
Input: "programming"
Output: 3
Q7 (Thinking Question)
What happens if the list is empty?
How should your program behave?
🔑 HINTS (Read Together, Only If Stuck)
Assume first element for min/max Use a flag variable (found = False) For reverse: create a new list or loop backwards Always think about empty input ✅ What You Should Be Able to Do Now
After Day 3, you should:
Store multiple values in a list Apply logic to each element Process strings as character lists Build real data-processing logic 🧠 Reflection Questions (Answer in Words)
Why do we use lists instead of many variables? What is difference between index and value? Why do we assume first element for max/min? Why does string behave like list? ⭐ Golden Rule from Day 3
Real programs are not about single values.
They are about collections of values.
If you say “Continue with Day 4”, next we’ll cover:
Breaking problems into pieces First step toward real software design One day at a time.